我正在为我们的网站创建一个文件上传实用程序,如果上传格式无效(根据我们的规范,不值得在这里查看),我想删除 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>
但无可否认,我很担心 cfexecute 标签的允许使用。
还有另一个选项,它使用 cfdirectory 递归删除选项,它可以满足我的所有要求,但我想非常确定它不会删除我指向的文件夹之外的文件夹/文件。
还有第三种方式,它涉及一个 cfdirectory 并围绕它循环,但我也喜欢使用更少的代码行来执行简单操作的想法。
你最信任哪个选项?
我正在运行 IIS7、Coldfusion 8。