我想寫一個腳本,將文件從文件夾A複製到文件夾B,它將只複製來自列表文件的文件。簡單的腳本與日誌
然後我需要它來記錄任何未能複製的文件。這是我到目前爲止,我只是無法登錄工作。
Option Explicit
Dim Sour, Dest
Dim oFSO, sFile, oFile, sText
Dim objFSO, objFileCopy
Dim strFilePath, strDestination, strSource
Const ForReading = 1, ForWriting = 2, ForAppending = 8
strLoggingFiles = "C:\failedtransfer.txt"
strSource = InputBox("Enter source path information") 'Enter your source path here
strDestination = InputBox("Enter destination path information") 'Enter your destination path here
'Set the read of the input file and prompt for location
Set oFSO = CreateObject("Scripting.FileSystemObject")
sFile = InputBox("Enter path to text document with files to be copied:")
'Open the read, get the file name of the file to be copied, and copy it to new location
If oFSO.FileExists(sFile) Then
Set oFile = oFSO.OpenTextFile(sFile, ForReading)
Do While Not oFile.AtEndOfStream
sText = oFile.ReadLine
If (Trim(sText) <> "") And _
oFSO.FileExists(strSource & "\" & sText) Then
oFSO.CopyFile strSource & "\" & sText, strDestination
Else
WScript.Echo "Couldn't find " & strSource & "\" & sText
End If
Loop
oFile.Close
Else
WScript.Echo "The file was not there."
End If
我沒有看到任何執行日誌記錄的代碼。你忘了寫嗎? – Jay
我試着編寫一些日誌代碼,但沒有任何工作,所以我發佈了工作的部分,在頂部可以看到strLoggingFiles,我在其中創建了日誌文件名。 –