2016-05-06 60 views
1

我嚴重不知道什麼是錯,誰能幫助:VBS告訴我對象不支持此屬性

Dim objFSO, objFolder, objFile, objNewFolder 

' Create the file system object/Assing the system object to a variable 
Set objFSO = CreateObject("Scripting.FileSystemObject") 

' Get the folder we want to copy files from 
Set objFSO = objFSO.GetFolder("C:\Test") 

' Create a new folder called Test2 
Set objNewFolder = objFSO.CreateFolder("C:\Test\Test2") 

' For each file in the folder, copy the file to the destination 
For Each objFile In objFolder.Files 
    objFile.Copy "C:\Test2" 
Next 

它告訴我說:

VBS對象不支持此屬性或方法:「CreateFolder」

回答

1

的問題是,你是重新分配objFSO成爲Folder對象返回這裏:

Set objFSO = objFSO.GetFolder("C:\Test") 

這條線之後,objFSO不再是Scripting.FileSystemObject,其一個Scripting.Folder對象。您需要將您的代碼更改爲:

Set objFolder = objFSO.GetFolder("C:\Test") 
+0

非常感謝! –

相關問題