Link to home
Start Free TrialLog in
Avatar of Aleks
AleksFlag for United States of America

asked on

Copy files from one folder to another

Hi,

I saved a file as a .bat

the file has the code below. It simply copies the files inside a folder into another folder.

xCopy /E/Y E:\source*.* E:\web\newfolder

Open in new window


The problem is that it is not doing it, the black screen comes up and closes right away. I can only see it reads 'files copied 0', but can't see the error. The paths are correct. Both folders exist.

Any ideas?
I am running this on Windows 2012R2
Avatar of Joe Winograd
Joe Winograd
Flag of United States of America image

> I can only see it reads 'files copied 0', but can't see the error.

Place a pause command in the batch file after the xcopy command and it will keep the window from closing so you'll be able to see the error message (which is probably going to be "Cannot perform a cyclic copy").

> Both folders exist.

source*.* is not a folder — it is a wildcard for files. Perhaps you meant this:

xcopy E:\source E:\web\newfolder /E/Y
pause

Open in new window


Regards, Joe
Avatar of ☠ MASQ ☠
☠ MASQ ☠

or did you mean to put:
xCopy  E:\source\*.* E:\web\newfolder /E /Y

Open in new window


to copy all files from folder "source"??

Beware also of long file names if the real name of "source" has spaces wrap the entire path in quotes
xCopy "E:\my long path name\*.*" "E:\web\my other long path name" /E /Y 

Open in new window


Another quick diagnostic is to simply open a CMD window and then paste your code in the command line, that way the window won't close.
proper syntax.. robocopy source destination options
> proper syntax.. robocopy source destination options

He's using xcopy, not robocopy.
xcopy /? will show its proper syntax.
Avatar of Aleks

ASKER

I meant files
SOLUTION
Avatar of Joe Winograd
Joe Winograd
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You must run the batch script at an elevated admin level - RIGHT-click on the batch file, select "Run as Administrator".
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Aleks

ASKER

Doesn't need admin. That didn't work. I'll try again tonight. The script seems to run fine in a different server
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Aleks

ASKER

Sorry I was away for a few days. I will add the pause command tonight and post the results
Sounds good.
Avatar of Aleks

ASKER

I checked and no errors, the problem is that its only copying one file, no folders or anything like that.

xCopy /E/Y E:\source\ASPS*.* E:\web\

Open in new window


It copies one ASP, the rest are not copied over.
Avatar of Aleks

ASKER

Strange, in fact it takes the folder ASPS and copies it over to the target /web/ folder adds the ASPS and some of the files there, not all.
Avatar of Aleks

ASKER

Found the issue, it was missing a \  

xCopy /E/Y E:\source\ASPS\*.*
Avatar of Aleks

ASKER

Thanks for the follow up
> problem is that its only copying one file, no folders or anything like that.

You're doing the same thing as I mentioned earlier. Please read my post #a42152923. ASPS*.* is a wildcard for files. Now read my post #a42153002, which shows that you probably want this:
E:\source\ASPS\*.*
Regards, Joe
When I hit Submit, I see that our messages crossed. Very glad to see that you figured it out! Regards, Joe
Avatar of Aleks

ASKER

Ha! .. Thanks Joe :)