Xcopy

ramitaherwahdan

New member
Local time
Today, 10:37
Joined
Feb 21, 2011
Messages
9
Dear All,

Thanks in advance for the help. I am trying to copy many files (reports as pdf) from one folder to another. I tried to do that with filecopy but the customers were complaining it takes too long. I try to use the shell command that makes the copy process faster as I heared.

I took the below code:

retval = Shell("XCOPY c:\DELL6400\*.* C:\test /E", 0)

and I tried to do the same as the above but with names for the path "from" and "to" because I retrieve them from the table in loop operation as below:

retval = Shell("XCOPY ") & filePath & " " & filePath2

but the code dont work! can someone help me on this :cool:

Thanks,
Rami
 
Closing bracket is in the wrong place.
 
Hi again,

I try to do the below,

retval = Shell("XCOPY " & filePath & " " & filePath2 & " /E", vbHide)

I dont get errors but no files were coppied! can you help me with the right code please?

Thanks,
Rami
 
Another idea is to send the output of the DOS to a file so you can see what it said.

retval = Shell("XCOPY " & filePath & " " & filePath2 & " /E /I >C:\log.txt", vbHide)
 
Another idea is to send the output of the DOS to a file so you can see what it said.

retval = Shell("XCOPY " & filePath & " " & filePath2 & " /E /I >C:\log.txt", vbHide)

I tried the code to copy to log file but it doesnt do that either! maybe the xcopy code is wrong!
 
what does filepath and filepath2 contain? if there are blanks, the lot must be wrapped in ""

As a test, do it in CMD window, once the thing works, copy the string into your shell, run it, once that works, replace the fixed filepaths with your variables. And in case of problems debug.print out your variables, and the entire string sent to the shell, to compare it with the original.
 
Last edited:
I tried through cmd and it did work. see attached!


OK, I got it to work but something on the way again! I put the code below:

retval = Shell("xcopy " & filePath & " " & filePath2)

but now I get a dos cmd prompet for every file asking if the object is a file or folder eventhough it is with extension .pdf at the end! how can I go around this? is there a switch that I can use to say to VBA that it is a file?

Thanks
 
how many files are there? moving hundreds of files may not be quick, especially if to a different drive letter.

you could use VBA directly

Dir and Name commands. Won't be any quicker, though.
 
but now I get a dos cmd prompet for every file asking if the object is a file or folder eventhough it is with extension .pdf at the end! how can I go around this? is there a switch that I can use to say to VBA that it is a file?

Are you using the /I switch?
 
Solved

Thanks everyone I just needed to add vbhide and in the folder path I needed to add "\" so that dos see it as folder path.

Cheers
 

Users who are viewing this thread

Back
Top Bottom