Windows Scripting
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsSystem AdministrationWindows Scripting

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old August 8th, 2008, 04:18 PM
Hangman Hangman is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2008
Posts: 29 Hangman User rank is Sergeant (500 - 2000 Reputation Level)Hangman User rank is Sergeant (500 - 2000 Reputation Level)Hangman User rank is Sergeant (500 - 2000 Reputation Level)Hangman User rank is Sergeant (500 - 2000 Reputation Level)Hangman User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 6 h 56 m 6 sec
Reputation Power: 0
'objFSObject.CopyFile' trouble

I am having some trouble getting this command to work.
In essence, I want to copy 100+ files from the server to several PC's connected to the server. Each user will run this script to get the files copied to their machine. (Although I eventually want to automate that step as well so the user doesn't have to do a thing.)
I'm not sure what I am missing, but I get the error: File not Found. Here's my code:
vb Code:
Original - vb Code
  1.  
  2. Dim objFSObject, objTerrDir, objTerrTrack, objRootDrive, objRootDir, objRootTrack, strRootDir, strFileList, objFile
  3. Set objFSObject = CreateObject("Scripting.FileSystemObject")
  4. Set objTerrDir = objFSObject.GetFolder("C:\Program Files\Terragen\TERAFORM")
  5. strRootDir = "\temp\Terragen\TERAFORM\Track_1"
  6.  
  7. Set objTerrTrack = objFSObject.GetFolder(objTerrDir & "\Track_1")
  8.  
  9. If objFSObject.DriveExists("X:") Then
  10.    Set objRootDrive = objFSObject.GetDrive("X:")
  11.   Else
  12.    MsgBox "You are not currently connected to the network." & vbCrLf & vbCrLf & _
  13.           "Please reboot your machine to connect to the server, or contact your " & _
  14.           "local I.T. admvinistator for assistance.", 0 + 48,
  15.    WScript.Quit
  16. End If
  17.  
  18. Set objRootDir = objFSObject.GetFolder(objRootDrive & strRootDir)
  19.  
  20. For Each objFile In objRootDir.Files
  21.    strFileList = strFileList & objFile.Name & vbCrLf
  22. Next
  23. MsgBox strFileList, ,"List of files in " & objRootDir 
  24.  ' I am getting the list of files
  25.  
  26. For Each objFile In objRootDir.Files
  27.    objFSObject.CopyFile objRootDir & objFile.Name, objTerrTrack
  28.  ' I am getting the error "File not found"
  29. Next
  30.  
  31.  ' I have also tried the following
  32.  ' objFSObject.CopyFile objRootDir & "*.env", objTerrTrack
  33.  ' objFSObject.CopyFile "X:\temp\Terragen\TERAFORM\Track_1", objTerrTrack
  34.  ' objFSObject.CopyFile "X:\temp\Terragen\TERAFORM\Track_1", "C:\Program Files\Terragen\TERAFORM\Track_1"
  35.  
  36. MsgBox "Finished copying files"
  37. WScript.Quit  'Terminate the script's execution
  38.  

I have read though the MSDN library on this topic, and I have my code as they suggest on the webpage.
The only thing I can think of is either I don't have the name correct for my server; < Drawings on 'sqlserver' (X: ) > (without the brackets of course)
or, I don't have my connection to my drive set properly. But neither of these make sense because I am getting a list of the files in the directory from the server.

I'm also not quite sure I need the For Each ... Next Loop either. From my pocket reference manual and the MSDN library, the objFSObject.CopyFile should copy all files in the directory if I am using the wildcard "*.env", so there's no need to loop.
But even without the loop, I'm getting the error.
Can you show me the error of my ways ??
Thanks.

Reply With Quote
  #2  
Old August 9th, 2008, 02:43 AM
Nilpo's Avatar
Nilpo Nilpo is offline
ASP Free Beginner (1000 - 1499 posts)
 
Join Date: Jun 2006
Location: Salem, OH
Posts: 1,254 Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)  Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 6 Days 10 h 25 m 34 sec
Reputation Power: 667
Send a message via ICQ to Nilpo Send a message via AIM to Nilpo Send a message via MSN to Nilpo Send a message via Yahoo to Nilpo Send a message via Google Talk to Nilpo Send a message via Skype to Nilpo Send a message via XFire to Nilpo
Facebook MySpace Orkut
The problem is in this line.
vb Code:
Original - vb Code
  1. objFSObject.CopyFile objRootDir & objFile.Name, objTerrTrack
You are providing objects as parameters. The CopyFile method only accepts text strings as parameters. Try this.
vb Code:
Original - vb Code
  1. objFSObject.CopyFile objFile.Path, objTerrTrack.Path
__________________
Click the image if at any point you don't like my decision.

Scripting problems? Windows questions? Ask the Windows Guru!


Reply With Quote
  #3  
Old August 11th, 2008, 06:19 PM
Hangman Hangman is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2008
Posts: 29 Hangman User rank is Sergeant (500 - 2000 Reputation Level)Hangman User rank is Sergeant (500 - 2000 Reputation Level)Hangman User rank is Sergeant (500 - 2000 Reputation Level)Hangman User rank is Sergeant (500 - 2000 Reputation Level)Hangman User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 6 h 56 m 6 sec
Reputation Power: 0
Quote:
Originally Posted by Nilpo
The problem is in this line.
vb Code:
Original - vb Code
  1. objFSObject.CopyFile objRootDir & objFile.Name, objTerrTrack
You are providing objects as parameters. The CopyFile method only accepts text strings as parameters. Try this.
vb Code:
Original - vb Code
  1. objFSObject.CopyFile objFile.Path, objTerrTrack.Path

Ok, I'm probably jumping the gun here but I'm going to put egg on my face anyway, ... HAAAAA !!! I think I've found something that'll stump you.
So, I tried what you suggested and I then received the error:
Object required: 'X:\temp\Terragen\TERA...'

I looked at this piece:
Quote:
FileSystemObject.CopyFile "c:\mydocuments\letters\*.doc", "c:\tempfolder\"
from the MSDN Library ,

and then looked at this piece:
Quote:
Set oFS = WScript.CreateObject("Scripting.FileSystemObject")
oFS.CopyFile "C:\zoomserv\data\Ds\00000006\import","C:\zoomserv\data\Ds\00000006\import.old"
from a support text , and wrote my line to reflect it like so:
vb Code:
Original - vb Code
  1. objFSObject.CopyFile strRootDir & "*.env", strTerrTrack
But I still get the error: 'file not found'.
Now I did notice on the support text, the destination file is singular and the source file isn't listed per se.
Could I possibly be using the wrong command ?? I'm getting the impression the .CopyFile is for individual files and not a whole slew of them.

Reply With Quote
  #4  
Old August 11th, 2008, 11:12 PM
Nilpo's Avatar
Nilpo Nilpo is offline
ASP Free Beginner (1000 - 1499 posts)
 
Join Date: Jun 2006
Location: Salem, OH
Posts: 1,254 Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)  Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 6 Days 10 h 25 m 34 sec
Reputation Power: 667
Send a message via ICQ to Nilpo Send a message via AIM to Nilpo Send a message via MSN to Nilpo Send a message via Yahoo to Nilpo Send a message via Google Talk to Nilpo Send a message via Skype to Nilpo Send a message via XFire to Nilpo
Facebook MySpace Orkut
If you're getting an object required error it most likely means that the script is not connecting to the remote server (or drive).

Are you trying to copy an entire directory?

Reply With Quote
  #5  
Old August 12th, 2008, 06:14 AM
Nilpo's Avatar
Nilpo Nilpo is offline
ASP Free Beginner (1000 - 1499 posts)
 
Join Date: Jun 2006
Location: Salem, OH
Posts: 1,254 Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)Nilpo User rank is Brigadier General (60000 - 70000 Reputation Level)  Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1Folding Points: 206875 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 6 Days 10 h 25 m 34 sec
Reputation Power: 667
Send a message via ICQ to Nilpo Send a message via AIM to Nilpo Send a message via MSN to Nilpo Send a message via Yahoo to Nilpo Send a message via Google Talk to Nilpo Send a message via Skype to Nilpo Send a message via XFire to Nilpo
Facebook MySpace Orkut
You're object error is coming from this line:
vb Code:
Original - vb Code
  1. Set objTerrTrack = objFSObject.GetFolder(objTerrDir & "\Track_1")
You can't use an object reference here. It needs to be a string value.
vb Code:
Original - vb Code
  1. Set objTerrTrack = objFSObject.GetFolder("C:\Program Files\Terragen\TERAFORM\Track_1")
You also need to remove the last comma from your MsgBox function. Leave it off if you aren't going to provide the optional parameter.

Here's your code rewritten. This should take care of any errors.
vb Code:
Original - vb Code
  1. Set objFSObject = CreateObject("Scripting.FileSystemObject")
  2. Set objTerrDir = objFSObject.GetFolder("C:\Program Files\Terragen\TERAFORM")
  3. strRootDir = "\temp\Terragen\TERAFORM\Track_1"
  4.  
  5. Set objTerrTrack = objFSObject.GetFolder("C:\Program Files\Terragen\TERAFORM\Track_1")
  6.  
  7. If objFSObject.DriveExists("X:") Then
  8.     Set objRootDrive = objFSObject.GetDrive("X:")
  9. Else
  10.     MsgBox "You are not currently connected to the network." & vbCrLf & vbCrLf & _
  11.             "Please reboot your machine to connect to the server, or contact your " & _
  12.             "local I.T. administrator for assistance.", 0 + 48
  13.     WScript.Quit
  14. End If
  15.  
  16. Set objRootDir = objFSObject.GetFolder(objRootDrive.Path & strRootDir)
  17.  
  18. For Each objFile In objRootDir.Files
  19.    strFileList = strFileList & objFile.Name & vbCrLf
  20. Next
  21. MsgBox strFileList, ,"List of files in " & objRootDir.Path
  22.  ' I am getting the list of files
  23.  
  24. For Each objFile In objRootDir.Files
  25.    objFSObject.CopyFile objRootDir.Path & objFile.Name, objTerrTrack.Path
  26.  ' I am getting the error "File not found"
  27. Next
  28.  
  29. MsgBox "Finished copying files"
  30. WScript.Quit  'Terminate the script's execution
  31.  
You need to be careful to pass the correct data types to your various functions and methods. A Folder object represents a physical folder, but does not represent the path to it. For that you will need the Path property of that folder object.

Reply With Quote
  #6  
Old August 12th, 2008, 12:07 PM
Hangman Hangman is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2008
Posts: 29 Hangman User rank is Sergeant (500 - 2000 Reputation Level)Hangman User rank is Sergeant (500 - 2000 Reputation Level)Hangman User rank is Sergeant (500 - 2000 Reputation Level)Hangman User rank is Sergeant (500 - 2000 Reputation Level)Hangman User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 6 h 56 m 6 sec
Reputation Power: 0
Nilpo, I really appreciate your help.
Quote:
Originally Posted by Nilpo
You need to be careful to pass the correct data types to your various functions and methods. A Folder object represents a physical folder, but does not represent the path to it. For that you will need the Path property of that folder object.
I am realizing this with your explanations and help, so thank you again.
I think I've got most of it figured out, with the exception of this continual error, "file not found".
I'd like to attach some pics of the return I'm getting, but I'm at a loss as to how this works on this board, so I'm going to post them instead. (I hope this works 'cause I'm getting confused) So, I run this ...
vb Code:
Original - vb Code
  1. Option Explicit
  2. Const cErrorMsg = "Directory Error"
  3. Dim objFSObject, objUserDir, objUserTrack, objRootDrive, objRootDir, objFile
  4. Dim strRootDir, strUserTrack, strFileList
  5. Set objFSObject = CreateObject("Scripting.FileSystemObject"