简体   繁体   中英

How can i move some files from a directory to an other directory using a batch script?

I used this command to move some files from a directory to an other using a batch script:

xcopy "pippo\*.*" /s "C:\Program Files (x86)\pippo2"

and it worked; it copied all files that are in the folder "pippo" to the folder "pippo2".

But when I have to run my .bat file as administrator it says that it can't find the file named *.* , but *.* indicate all files with all extension that are into the folder named "pippo" ! So, why does it say that it can't find the file *.* , what's wrong in my command ?

It's probably where you are running the batch file from. When you elevate to administrative rights, I believe the default location is C:\\Windows\\System32 . Try using full file path in your batch file.

This batch will copy from the directory pippo relative to your current directory. In all probability, the current directory when run as administrator is different from the current directory when run as a user .

You could check this by inserting some code before and after:

echo %cd%
xcopy "pippo\*.*" /s "C:\Program Files (x86)\pippo2"
pause

(just temporarily)

If the directory shown is different in the two modes, then you need to change the directory in administrator mode or specify exactly where pippo is,

xcopy "c:\full\path\to\pippo\*.*" /s "C:\Program Files (x86)\pippo2"

try this, please specify full path.

xcopy "D:\yourSourceFolder\" /S "E:\yourDest\"

or

xcopy "D:\yourSourceFolder\*.*" /S "E:\yourDest\"

don't forget trailing slash in the dest folder , or dos will treat you is this file or folder.

Thanks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM