【发布时间】:2011-06-12 04:49:47
【问题描述】:
将所有文件从一个文件夹移动到另一个文件夹的最佳命令是什么?
我想在批处理文件中执行此操作。
【问题讨论】:
-
什么操作系统和外壳?
标签: batch-file cmd command-prompt
将所有文件从一个文件夹移动到另一个文件夹的最佳命令是什么?
我想在批处理文件中执行此操作。
【问题讨论】:
标签: batch-file cmd command-prompt
您可以为此使用move。 help move 的文档指出:
Moves files and renames files and directories.
To move one or more files:
MOVE [/Y | /-Y] [drive:][path]filename1[,...] destination
To rename a directory:
MOVE [/Y | /-Y] [drive:][path]dirname1 dirname2
[drive:][path]filename1 Specifies the location and name of the file
or files you want to move.
destination Specifies the new location of the file. Destination
can consist of a drive letter and colon, a
directory name, or a combination. If you are moving
only one file, you can also include a filename if
you want to rename the file when you move it.
[drive:][path]dirname1 Specifies the directory you want to rename.
dirname2 Specifies the new name of the directory.
/Y Suppresses prompting to confirm you want to
overwrite an existing destination file.
/-Y Causes prompting to confirm you want to overwrite
an existing destination file.
The switch /Y may be present in the COPYCMD environment variable.
This may be overridden with /-Y on the command line. Default is
to prompt on overwrites unless MOVE command is being executed from
within a batch script.
请参阅以下脚本以获取最初显示 qq1 和 qq2 目录分别包含三个文件和没有文件的示例。然后,我们执行move,我们发现三个文件已经按预期从qq1移动到qq2。
C:\Documents and Settings\Pax\My Documents>dir qq1
Volume in drive C is Primary
Volume Serial Number is 04F7-0E7B
Directory of C:\Documents and Settings\Pax\My Documents\qq1
20/01/2011 11:36 AM <DIR> .
20/01/2011 11:36 AM <DIR> ..
20/01/2011 11:36 AM 13 xx1
20/01/2011 11:36 AM 13 xx2
20/01/2011 11:36 AM 13 xx3
3 File(s) 39 bytes
2 Dir(s) 20,092,547,072 bytes free
C:\Documents and Settings\Pax\My Documents>dir qq2
Volume in drive C is Primary
Volume Serial Number is 04F7-0E7B
Directory of C:\Documents and Settings\Pax\My Documents\qq2
20/01/2011 11:36 AM <DIR> .
20/01/2011 11:36 AM <DIR> ..
0 File(s) 0 bytes
2 Dir(s) 20,092,547,072 bytes free
C:\Documents and Settings\Pax\My Documents>move qq1\* qq2
C:\Documents and Settings\Pax\My Documents\qq1\xx1
C:\Documents and Settings\Pax\My Documents\qq1\xx2
C:\Documents and Settings\Pax\My Documents\qq1\xx3
C:\Documents and Settings\Pax\My Documents>dir qq1
Volume in drive C is Primary
Volume Serial Number is 04F7-0E7B
Directory of C:\Documents and Settings\Pax\My Documents\qq1
20/01/2011 11:37 AM <DIR> .
20/01/2011 11:37 AM <DIR> ..
0 File(s) 0 bytes
2 Dir(s) 20,092,547,072 bytes free
C:\Documents and Settings\Pax\My Documents>dir qq2
Volume in drive C is Primary
Volume Serial Number is 04F7-0E7B
Directory of C:\Documents and Settings\Pax\My Documents\qq2
20/01/2011 11:37 AM <DIR> .
20/01/2011 11:37 AM <DIR> ..
20/01/2011 11:36 AM 13 xx1
20/01/2011 11:36 AM 13 xx2
20/01/2011 11:36 AM 13 xx3
3 File(s) 39 bytes
2 Dir(s) 20,092,547,072 bytes free
【讨论】:
move c:\sourcefolder c:\targetfolder
会起作用,但你最终会得到这样的结构:
c:\targetfolder\sourcefolder\[all the subfolders & files]
如果您只想将一个文件夹的内容移动到另一个文件夹,那么应该这样做:
SET src_folder=c:\srcfold
SET tar_folder=c:\tarfold
for /f %%a IN ('dir "%src_folder%" /b') do move "%src_folder%\%%a" "%tar_folder%\"
pause
【讨论】:
move c:\sourcefolder\* c:\targetfolder 将移动 sourcefolder 的 content 而不是移动源文件夹。
此命令会将原始文件夹中的所有文件移动到目标文件夹。
MOVE c:\originalfolder\* c:\destinationfolder
(但它不会将任何子文件夹移动到新位置。)
要查找 MOVE 命令的说明,请在 Windows 命令提示符中键入:
MOVE /?
【讨论】:
在 Windows 上查找 move /?,在 Unix 系统上查找 man mv
【讨论】:
move --help?在 Windows 上?真的吗?你试过吗? :-) 我想你的意思是move /? 或help move。
move --help 的结果是 The system cannot find the file specified.。
robocopy 似乎是最通用的。在帮助中查看它的其他选项
robocopy /?
robocopy SRC DST /E /MOV
【讨论】:
/MOV 选项表示“移动文件,并在复制后从源中删除它们”,/E 表示“复制子目录”。这有效地将所有文件移出源文件夹及其子文件夹,并在目标文件夹下重新创建文件夹结构,为您留下一个空的源文件夹和结构;如果不存在,它也会创建目标文件夹。 Robocopy 非常强大,here's the documentation。特别注意/MOVE 选项(与上面的/MOV 相对)。
【讨论】:
如果文件路径中有空格,请务必使用引号:
move "C:\Users\MyName\My Old Folder\*" "C:\Users\MyName\My New Folder"
这会将C:\Users\MyName\My Old Folder\ 的内容移动到C:\Users\MyName\My New Folder
【讨论】:
使用move
然后move <file or folder> <destination directory>
【讨论】:
天哪,我得到了一个 快速文件移动命令 表单 CMD
1) 命令将在 1 秒内将所有文件和子文件夹移动到另一个位置。
检查命令
C:\user>move "your source path " "your destination path"
提示:用于移动所有文件和子文件夹
C:\user>move "f:\wamp\www" "f:\wapm_3.2\www\old Projects"
您可以看到它是在我尝试其他一些由于超过 1 个文件和文件夹而无法正常工作的代码之前。当我尝试执行红色线条下的代码时,所有文件夹都会在 1 秒内移动。
现在检查这张图片。 这里 1 秒内总共移动了 6.7GB 数据...您可以查看发布日期和移动日期以及文件夹名称。
我很快就会制作一个可以做到这一点的 Windows 应用程序..
【讨论】: