2016-05-24 38 views
0

我有一個VB腳本文件 - main.vbs。其內容是:vbscript - 如果有任何文件存在,然後複製和重命名

Set fileSystemObject = CreateObject("Scripting.FileSystemObject") 
If fileSystemObject.FileExists("D:\a\source.doc") Then 
fileSystemObject.CopyFile "D:\b\template.doc", "D:\c\source.doc" 
fileSystemObject.MoveFile "D:\a\source.doc" , "D:\d\" 
End If 

這是什麼腳本是:它檢查通過的「source.doc」名稱的文件夾中存在「d:\ A」。 (i)複製保存在文件夾'D:\ b'中的文件'template.doc' (ii)將「template.doc」重命名爲「source.doc」 ( iii)並將這個重命名的文件移動到文件夾'D:\ c'。 (iv)並且將文件'source.doc'從'D:\ a'移動到'D:\ d'

腳本工作正常。但我希望腳本應該在文件名'source'變化時運行(但擴展名相同.doc)。

文件名'template.doc'保持不變。

我該怎麼做?

回答

0

這使用FSO對象更像是一個目錄。對名稱進行測試以決定是否處理它。 fso.copyfile與使用集合和For Each循環的thing.copy相同。

'On Error Resume Next 
Set fso = CreateObject("Scripting.FileSystemObject") 
Dirname = InputBox("Enter Dir name") 
ProcessFolder DirName 

Sub ProcessFolder(FolderPath) 
' On Error Resume Next 
Set fldr = fso.GetFolder(FolderPath) 

Set Fls = fldr.files 

For Each thing in Fls 
    msgbox Thing.Name & " " & Thing.DateLastModified 
Next 

'Uncomment below lines to do sub folders 
' Set fldrs = fldr.subfolders 
' For Each thing in fldrs 
'  ProcessFolder thing.path 
' Next 

End Sub 
+0

我想我對vbscript不是很熟練。任何支持,我可以得到請 – vicki

+0

任何幫助,我可以得到這個請 – vicki

+0

https://www.microsoft.com/en-au/download/details.aspx?id=2764是VBScript幫助。用你試過的東西編輯你的問題。 –

相關問題