将所有文件从一个文件夹移动到另一个文件夹的最佳命令是什么?
我想在批处理文件中执行此操作。
答案 0 :(得分:51)
您可以使用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
答案 1 :(得分:30)
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
答案 2 :(得分:17)
此命令会将originalfolder中的所有文件移动到目标文件夹。
MOVE c:\originalfolder\* c:\destinationfolder
(但是它不会将任何子文件夹移动到新位置。)
要查找MOVE命令的说明,请在Windows命令提示符中键入:
MOVE /?
答案 3 :(得分:4)
在Windows上查找move /?
,在Unix系统上查找man mv
答案 4 :(得分:3)
答案 5 :(得分:2)
使用move
然后move <file or folder> <destination directory>
答案 6 :(得分:2)
robocopy /?
robocopy SRC DST /E /MOV
答案 7 :(得分:1)
如果文件路径中有空格,请确保使用引号:
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
答案 8 :(得分:0)
OMG我收到了快速文件移动命令表格 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秒钟内移动。
现在检查此图像。 此处总共6.7GB的数据在1秒内移动 ......您可以查看发布和移动的日期以及文件夹名称。
我很快就会制作一个可以执行相同操作的Windows应用程序。
答案 9 :(得分:-1)
要移动子目录(包括空文件夹),您可以使用复制和删除的组合:
# Setting up test env...
C:\> mkdir folder1 folder1\sub1 folder1\sub2 folder2
C:\> touch folder1\sub1\file.txt
# Copy "folder1" to "folder2", then remove "folder1"
C:\> xcopy /e folder1 folder2
C:\> rmdir /s /q folder1