简体   繁体   English

如何使用批处理脚本将某些文件从目录移动到另一个目录?

[英]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.

相关问题 如何使用批处理脚本从当前目录复制文件,而不复制子目录? - How do I copy files from the current directory, but not sub-directories using a batch script? 如何使用批处理脚本使用另一个目录的子文件夹名称在目录中创建新的空文件夹? - How can I create new empty folders in a directory using names of subfolders of another directory using batch script? Windows批处理脚本,用于将所有文件从Windows中的一个目录移动到另一个目录,并且文件夹中包含空格 - Windows Batch Script to move all files from one directory to another in windows, and folder contains spaces 批处理文件使用多个文本文件将文件移动到另一个目录 - Batch File Move files using multiple text files into another directory 批处理:如何根据文件名将文件复制到目录 - BATCH: How can I copy files to directory based on file name 批处理命令将文件从子目录移动到新目录 - Batch Command to Move Files from Sub Directories to New Directory 如何使用批处理脚本创建没有文件类型扩展名的文件夹名称并移入创建的子目录? - How to create folder name without extension of file type using batch script and move in created sub directory? 如何将文件从一个目录移动到另一个目录? - How to move files from a directory to another? 使用chdir后如何验证批处理文件中的目录 - How can I verify directory in batch file after using chdir 用于将文件移动到新目录的批处理命令 - Batch command to move files to a new directory
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM