VBS告诉我对象不支持此属性

时间:2016-05-06 17:41:42

标签: vbscript create-directory

我真的不知道什么是错的,任何人都可以帮忙:

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 个答案:

答案 0 :(得分:1)

问题是您重新分配 objFSO成为此处返回的Folder对象:

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

在此行之后,objFSO不再是Scripting.FileSystemObject,而是Scripting.Folder对象。您需要将代码更改为:

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