cro*_*lum 1 directory coldfusion coldfusion-8
我正在为我们的网站创建一个文件上传实用程序,如果上传的格式无效(根据我们的规格,这里不值得),我想删除zip文件解压缩到的文件夹及其所有内容.
到目前为止,我已经使用了一种创建动态批处理文件的方法,如下所示:
<!--- check if folder exists before starting to delete --->
<cfif directoryexists("#file_path_course#")>
<!--- this can be passed in a varaible or whatever --->
<cfset tDirectory = "#file_path_course#">
<!--- This is what we will put in the bat file --->
<cfset tString ="RMDIR /S /Q " & tDirectory>
<!--- generate a .BAT file for later execution --->
<cffile action="WRITE" file="#file_path_course#\delete.bat" output="#tString#">
<!--- Now execute the file to delete everything (Folder and all sub-folders and files)--->
<cfexecute name="#file_path_course#\delete.bat" timeout="60"></cfexecute>
<!--- check if bat file exists --->
<cfif fileexists("#file_path_course#\delete.bat")>
<!--- now delete the bat file --->
<cffile action="DELETE" file="#file_path_course#\delete.bat">
</cfif>
<!--- delete course folder --->
<cfdirectory action="delete" directory="#file_path_course#" recurse="yes">
<cfset course_files_deleted = "Yes">
</cfif>
Run Code Online (Sandbox Code Playgroud)
但我确实担心允许使用cfexecute标签.
还有另一个选项,它使用cfdirectory recurse删除选项,这将完成我要求的所有,但我想非常确定它不会删除我指向它的文件夹之外的文件夹/文件.
有一种第三种方式,它涉及一个cfdirectory并循环它,但我也喜欢使用较少的代码行来做一个简单的操作.
您最信任哪个选项?
我正在运行IIS7,Coldfusion 8.
| 归档时间: |
|
| 查看次数: |
3928 次 |
| 最近记录: |