'===DeleteTempFiles.vbs=== 'from Michael Harris 'http://groups.google.com/groups?threadm=%23bXVsIHnAHA.920%40tkmsftngp02 Const TemporaryFolder = 2 'for GetSpecialFolder set fso = createobject("scripting.filesystemobject")
Kod:'===DeleteTempFiles.vbs=== 'from Michael Harris 'http://groups.google.com/groups?threadm=%23bXVsIHnAHA.920%40tkmsftngp02 Const TemporaryFolder = 2 'for GetSpecialFolder set fso = createobject("scripting.filesystemobject") 'init an empty array (ubound will be -1)... ' 'we use an array and store the file objects. 'this avoids any problems with altering the 'contents of the Files collections while they 'are being iterated. ' arFiles = array() count = -1 'get the path to the temp folder ' tempdir = fso.GetSpecialFolder(TemporaryFolder) 'load the (global scope) arFiles 'SelectFiles calls itself recursively 'for SubFolders ' SelectFiles tempdir msgbox count+1 & " files found" 'now do the actual deletes. the error trap 'is in case any are in-use... ' dcount = 0 for each file in arFiles on error resume next file.delete true if err.number = 0 then dcount = dcount + 1 err.clear on error goto 0 next 'now go back and delete empty folders 'below the temp folder DeleteEmptyFolders tempdir,false 'comment out for "silent" operation, 'or add support for a "/s" command-line switch. ' msgbox count+1 & " files found, " & dcount & " deleted." sub SelectFiles(sPath) 'select files to delete and add to array... ' set folder = fso.getfolder(sPath) set files = folder.files for each file in files count = count + 1 redim preserve arFiles(count) set arFiles(count) = file next for each fldr in folder.subfolders SelectFiles fldr.path next end sub sub DeleteEmptyFolders(sPath,bDeleteThisFolder) set folder = fso.getfolder(sPath) 'recurse first... ' for each fldr in folder.subfolders DeleteEmptyFolders fldr.path,true next 'if no files or folders then delete... ' 'bDeleteThisFolder is false for 'the root of the subtree, and true for 'sub-folders (unless you want to delete 'the entire subtree if it is empty). ' if (folder.files.count = 0) and _ (folder.subfolders.count) = 0 and _ bDeleteThisFolder then folder.delete exit sub end if end sub ' '===end-script===
Buraya da bakabilirsiniz..
Şu anda 1 kullanıcı bu konuyu görüntülüyor. (0 kayıtlı ve 1 misafir)