Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

copy folder help 1

Status
Not open for further replies.

Alex2020

IS-IT--Management
Apr 27, 2004
2
US
I'm teaching myself VBscript and for my first script I just want to copy one folder from another. I get a "wrong number of arguments or invalid property assignment" for line 4 char 1. I don't understand what I did wrong, can someone help me? Here's the code:

strcomputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strcomputer & "\root\cimv2")
Set colFolders = objWMIService.ExecQuery _
& "SELECT * FROM Win_32 Directory WHERE Name = 'C:\\tomcat'"
For Each objFolder in colFolders
errResults = objFolder.Copy("C:\Program Files\")
Wscript.Echo errResults
Next

 
IMO the file system object is much better for this. For example to do what you are trying to do here, you could:
Code:
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFOlder("C:\Tomcat")
Set colFiles = oFolder.Files
For Each oFile In colFiles
    oFile.copy("C:\Program Files\" & oFile.Name)
Next

Or better yet:
Code:
Set oFSO = CreateObject("Scripting.FileSystemObject")
oFSO.CopyFile("C:\Tomcat\*.*", "C:\Program Files")

Note that all of these will take the files that are in the tomcat dir and put them at the root of the program files dir. I suspect this isn't really what you want. If what you really wnat is to create a Tomcat folder and copy the files from c:\Tomcat to c:\program Files\Tomcat, then a better solution would be CopyFolder:
Code:
Set oFSO = CreateObject("SCripting.FileSystemObject")
oFSO.CopyFolder("C:\Tomcat", "C:\Program Files")
You should also know that this will copy the folder recursively. Thus it will get all of the subfolders as well.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top