文件 DelEmpt.js 代码:
//Function: Delete empty folders inside on folder, including/excluding zero-size folders. //Version: 1.0 //Author: ibic.
/*用法说明: **1。将此教本放入想要删除的文件夹里,双击此脚本。 **--或者-- **2。将想要删除的文件夹拖到这个脚本的图标上。 **!注意!: **此脚本默认将删除只含有0大小的文件的文件夹,如果想保留这种文件夹,请将最后一行改为: **DelEmptExc(f); */
//Recursively delete empty folders EXCluding zero-size files. function DelEmptExc(thefolder) { var fso, f, fsub; fso = new ActiveXObject("Scripting.FileSystemObject"); f = fso.GetFolder(thefolder); if(f.Size == 0) { fsub = new Enumerator(f.SubFolders); if(fsub.atEnd()) //Contains no subfolder. { fsub = new Enumerator(f.Files); if(fsub.atEnd()) //Contians no files. f.Delete(true); } } else { fsub = new Enumerator(f.SubFolders); for(; !fsub.atEnd(); fsub.moveNext()) DelEmptExc(fsub.item()); } }
//Recursively delete empty folders INCluding zero-size files. function DelEmptInc(thefolder) { var fso, f, fsub; fso = new ActiveXObject("Scripting.FileSystemObject"); f = fso.GetFolder(thefolder); if(f.Size == 0) //If the folder size is zero, delete the folder directly without recursing. f.Delete(true); else { fsub = new Enumerator(f.SubFolders); for(; !fsub.atEnd(); fsub.moveNext()) DelEmptInc(fsub.item()); } }
//The script entry is here. var f; if(WScript.Arguments.length == 0) f = "."; //If no args, delete in the current directory. else f = WScript.Arguments(0); //Else, delete the specified directory.
DelEmptInc(f); //Change this line if you want to change the deleting behavior.
|