[英]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".
它将文件夹“ pippo”中的所有文件复制到文件夹“ 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" ! 但是,当我必须以管理员身份运行.bat文件时,它说它找不到名为
*.*
的文件,但是*.*
表示所有具有所有扩展名的文件都位于名为“ 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
. 提升为管理权限时,我相信默认位置为
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. 该批次将从相对于您当前目录的目录
pippo
复制。 In all probability, the current directory
when run as administrator is different from the current directory when run as a user
. 极有可能,以管理员身份运行时的
current directory
不同于以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, 如果两种模式下显示的目录不同,则需要以管理员模式更改目录或确切指定
pippo
位置,
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. 不要忘记dest文件夹中的尾部斜杠,否则dos会将您视为此文件或文件夹。
Thanks. 谢谢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.