我需要一個重命名文件並將其從一個文件夾移動到另一個文件夾的VBScript。該腳本目前正確地重命名文件,但我無法弄清楚如何在重命名後將文件移動到新文件夾。將文件重命名後將文件移動到新文件夾
下面是它存在的腳本。
Option Explicit
Const SAVE_LOCATION = "\\pccit2\Int\PC\Inbox"
Const strPath = "D:\Files\pak\VP\"
Const StrPrefix = "VP"
Dim FSO
Dim FLD
Dim fil
Dim strOldName
Dim strNewName
Set FSO = CreateObject("Scripting.FileSystemObject")
Set FLD = FSO.GetFolder(strPath)
For Each fil In FLD.Files
strOldName = fil.Path
strNewName = strPath & strPrefix & Right(strOldName, 10)
FSO.MoveFile strOldName, strNewName
Next
For Each fil In FLD.Files
If strNewName = 1 Then
FSO.MoveFile "\\pccit2\Int\PC\Inbox"
End If
Next
Set FLD = Nothing
Set FSO = Nothing
我試過了各種方式讓文件移動。這裏有一些其他的嘗試:
If FSO.FileExists("D:\Files\pak\VP\*.*") Then
FSO.MoveFile "D:\Files\pak\VP\*.*", "\\pccit2\Int\PC\Inbox\*.*"
End If
的另一種嘗試
If fil.FileExists("D:\Files\pak\VP\*.*") Then
fil.MoveFile "D:\Files\pak\VP\*.*" , "\\pccit2\Int\PC\Inbox\*.*"
End If
謝謝!這非常有用,我會參考你的迴應。你提供的第一個腳本完美地工作。只有修改是在VP中添加一個前綴。我在這裏添加了它。 strNewName = FSO.BuildPath(SAVE_LOCATION,**「VP」**&Right(fil.Name,10)) – jodies