0

以下は、DAT ファイルを削除するための私のコードです。

OPTION EXPLICIT
DIM strExtensionsToDelete,strFolder
DIM objFSO, MaxAge, IncludeSubFolders

' ************************************************************
' Setup
' ************************************************************

' Folder to delete files
strFolder = "E:\test"
' Delete files from sub-folders?
includeSubfolders = true
' A comma separated list of file extensions
' Files with extensions provided in the list below will be deleted
strExtensionsToDelete = "dat"
' Max File Age (in Days).  Files older than this will be deleted.
maxAge = 0

' ************************************************************

set objFSO = createobject("Scripting.FileSystemObject")

DeleteFiles strFolder,strExtensionsToDelete, maxAge, includeSubFolders

wscript.echo "Finished"

sub DeleteFiles(byval strDirectory,byval strExtensionsToDelete,byval maxAge,includeSubFolders)
DIM objFolder, objSubFolder, objFile
DIM strExt

set objFolder = objFSO.GetFolder(strDirectory)
for each objFile in objFolder.Files
    for each strExt in SPLIT(UCASE(strExtensionsToDelete),",")
        if RIGHT(UCASE(objFile.Path),LEN(strExt)+1) = "." & strExt then
            IF objFile.DateLastModified < (Now - MaxAge) THEN
                wscript.echo "Deleting:" & objFile.Path & " | " & objFile.DateLastModified 
                objFile.Delete
                exit for
            END IF
        end if
    next
next    
if includeSubFolders = true then ' Recursive delete
    for each objSubFolder in objFolder.SubFolders
        DeleteFiles objSubFolder.Path,strExtensionsToDelete,maxAge,includeSubFolders
    next
end if
end sub

ここで、削除されたファイルの情報 (ファイルの名前、スクリプトの実行時、このスクリプトを実行したユーザーなど) を保存するログ ファイルを作成します。誰でもこれで私を助けることができますか?

前もって感謝します..

4

1 に答える 1

1

私はあなたのスタイルのパターンに行く必要がある場合.

' outside your DeleteFiles()
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set LogFile = objFSO.CreateTextFile(objFSO.GetTempName)
LogFile.WriteLine "DateTime: " & Now
LogFile.WriteLine "UserName: " & CreateObject("WScript.NetWork").UserName

DeleteFiles ...

' outside your DeleteFiles()
LogFile.Close

WScript.Echo "Finished"

Sub DeleteFiles(...

    ' inside For..Next in DeleteFiles()
    LogFile.WriteLine objFile.Path

End Sub
于 2013-02-18T14:19:00.743 に答える