0

ソース: ネットワークの場所 UNC パス 宛先: リモート サーバーであり、このサーバーでスクリプトを実行したいと考えています。

私は多くのスクリプトを探してきましたが、正確な要件を満たすことができませんでした。以下は私の要件に近いVBscriptですが、これはサブフォルダーでは機能せず、時間固有のように見え、複数のファイルタイプの特定の日を探しています。どんな助けでも大歓迎ですか?

助けてくれてありがとう!

他のスクリプトでも問題ありませんが、要件を満たす必要があります。

================================================== ====

Option Explicit 

On Error Resume Next

Dim fso, FileSet, Path, File, DDiff, Date1, Date2, DestPath

Path = "C:\source"
DestPath = "\\server\destination\" 
'DestPath must end with \
FileSet = GetDirContents(Path) 

For each File in FileSet 
Set File = fso.GetFile(Path & "\" & File)
Date1 = File.DateLastModified 
'.DateCreated if you want 24hrs of life, this example is 24hrs since last written
Date2 = Now()

DDiff = Abs(DateDiff("h", Date1, Date2))

If DDiff >= 168 Then
If Not fso.FileExists(DestPath & File.Name) Then
File.Move DestPath
'wscript.echo File.Name
Else
wscript.echo "Unable to move file [" & File.Name & "]. A file by this name already exists in the target directory."
End If
End If
Next 

Function GetDirContents(FolderPath) 
Dim FileCollection, aTmp(), i 
Set fso = CreateObject("Scripting.FileSystemObject") 
Set FileCollection = fso.GetFolder(FolderPath).Files 

Redim aTmp(FileCollection.count - 1) 
i = -1 

For Each File in FileCollection 
i = i + 1 
aTmp(i) = File.Name 
Next 

GetDirContents = aTmp 
End Function

================================================== ======================

4

1 に答える 1

0

DateDiff"h" (時間) の代わりに "d" を間隔 (日) として関数を使用できます。そして残りの問題は、この再帰関数をどのように作成するかですよね?

MoveByDate "C:\ソース", "\サーバー\宛先\", 7

Sub MoveByDate(SrcPath, DestPath, DaysDiff)
    Dim oFSO, oFile, oFolder, oSubFolder, Date1, Date2
    Set oFSO = CreateObject("Scripting.FileSystemObject")
    Set oFolder = oFSO.GetFolder(SrcPath)
    Date1 = Now

    For Each oFile In oFolder.Files
        Date2 = oFile.DateLastModified
        If Abs(DateDiff("d", Date1, Date2)) >= DaysDiff Then
            If Not oFSO.FileExists(DestPath & oFile.Name) Then
                oFile.Move DestPath
            End If
        End If
    Next

    For Each oSubFolder In oFolder.SubFolders
        MoveByDate oSubFolder, DestPath, DaysDiff
    Next
End Sub
于 2013-02-18T09:06:08.487 に答える