Patrick Miller
asked on
Copying files from one pc to another with CopyFile
I am copying files with this script and I am getting an error
Permission denied
Here is the script.
Set objFSO = CreateObject("Scripting.Fi leSystemOb ject")
objFSO.CopyFile "c:\Program Files\ADT\edge\*.*", "\\cw10072\c$\Program Files\ADT\edge\"
I can copy files from my pc to the cw10072 pc through Windows but I get the Permission error when I try to run this script. What am I doing wrong.
I also took the Copy "c:\Program Files\ADT\edge\*.*", "\\cw10072\c$\Program Files\ADT\edge\" in the command prompt and it worked fine.
Permission denied
Here is the script.
Set objFSO = CreateObject("Scripting.Fi
objFSO.CopyFile "c:\Program Files\ADT\edge\*.*", "\\cw10072\c$\Program Files\ADT\edge\"
I can copy files from my pc to the cw10072 pc through Windows but I get the Permission error when I try to run this script. What am I doing wrong.
I also took the Copy "c:\Program Files\ADT\edge\*.*", "\\cw10072\c$\Program Files\ADT\edge\" in the command prompt and it worked fine.
ASKER
I tried using the CopyFolder and it comes up with an error.
Path not found.
Path not found.
ASKER
I tried using the copyfile option and it runs for a bit then I get the pop-up error Permission denied. I am admin with full rights so I am not sure why this is happening.
Hello Patrick
what r the OS involved in this copying?? if u r using NT,W2K or XP or Win2003 ur program will not be allowed access to copy/paste file between systems u need to use a API - WNetAddConnection2 to establish a connection between the computers before attempting to use FSO.CopyFile, there is no problem in copying files on network it works fantastic.
My code is too long to paste it here, but u can find example of using above API on net easily.
all the best
what r the OS involved in this copying?? if u r using NT,W2K or XP or Win2003 ur program will not be allowed access to copy/paste file between systems u need to use a API - WNetAddConnection2 to establish a connection between the computers before attempting to use FSO.CopyFile, there is no problem in copying files on network it works fantastic.
My code is too long to paste it here, but u can find example of using above API on net easily.
all the best
ASKER
Do you have a good place you would recommend for examples of API on the web?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
here are the declarations for above api
Private Declare Function WNetAddConnection2 Lib "mpr.dll" Alias "WNetAddConnection2A" (lpNetResource As NETRESOURCE, ByVal lpPassword As String, ByVal lpUsername As String, ByVal dwFlags As Long) As Long
Private Declare Function WNetAddConnection2 Lib "mpr.dll" Alias "WNetAddConnection2A" (lpNetResource As NETRESOURCE, ByVal lpPassword As String, ByVal lpUsername As String, ByVal dwFlags As Long) As Long
aelatik,
Actually, you can use wildcards when using FSO to copy files. I have attached an exaple from code that I have written that combines the wildcard with other characters. What I use this for is to copy certain files to removable disk drives based on that drive's disk label (as opposed to its drive letter).
In the example, my variable is w and the script copies all files using both that and the wildcard. So if the variable w was assigned a text string of "Week1" the command (in DOS) would look like
Copy V:\A*Week1.* (to destination)
Actually, you can use wildcards when using FSO to copy files. I have attached an exaple from code that I have written that combines the wildcard with other characters. What I use this for is to copy certain files to removable disk drives based on that drive's disk label (as opposed to its drive letter).
In the example, my variable is w and the script copies all files using both that and the wildcard. So if the variable w was assigned a text string of "Week1" the command (in DOS) would look like
Copy V:\A*Week1.* (to destination)
objFSO.CopyFile "V:\A*"&w&".*" , objItem.DriveLetter, OverwriteExisting
Dim objFSO, objFolder, objFiles, objFile
Set objFSO = CreateObject("Scripting.Fi
Set objFolder = objFSO.GetFolder("c:\Progr
Set objFiles = objFolder.Files
For Each objFile In objFiles
objFSO.CopyFile objFile.Path, "\\cw10072\c$\Program Files\ADT\edge\", True
Next
Set objFSO = Nothing
Set objFolder = Nothing
Set objFiles = Nothing
For copyFolder use :
Dim objFSO
Set objFSO = CreateObject("Scripting.Fi
objFSO.CopyFolder "c:\Program Files\ADT\edge\", "\\cw10072\c$\Program Files\ADT\", True ' True = Overwrite
Set objFSO = Nothing