如何使用命令行将所有文件从一个文件夹移动到另一个文件夹?

Chi*_*rag 51 cmd batch-file command-prompt

将所有文件从一个文件夹移动到另一个文件夹的最佳命令是什么?

我想在批处理文件中执行此操作.

pax*_*blo 56

你可以用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.
Run Code Online (Sandbox Code Playgroud)

请参阅以下脚本,以获取最初显示qq1qq2目录分别具有三个文件和无文件的示例.然后,我们做的move,我们发现这三个文件已从移动qq1qq2预期.

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
Run Code Online (Sandbox Code Playgroud)

 

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
Run Code Online (Sandbox Code Playgroud)

 

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
Run Code Online (Sandbox Code Playgroud)


Jos*_*ons 31

move c:\sourcefolder c:\targetfolder
Run Code Online (Sandbox Code Playgroud)

会工作,但你最终会得到这样的结构:

c:\targetfolder\sourcefolder\[all the subfolders & files]
Run Code Online (Sandbox Code Playgroud)

如果您只想将一个文件夹的内容移动到另一个文件夹,那么应该这样做:

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
Run Code Online (Sandbox Code Playgroud)

  • 为了避免(可能)不需要的crooket文件夹结构,我发现asterix在源文件夹中修复了这个问题,即`move c:\ sourcefolder\*c:\ targetfolder`将移动sourcefolder的*content*而不是移动源文件夹. (5认同)

P.T*_*pie 18

此命令将原始文件夹中的所有文件移动到目标文件夹.

MOVE c:\originalfolder\* c:\destinationfolder
Run Code Online (Sandbox Code Playgroud)

(但是它不会将任何子文件夹移动到新位置.)

要查找MOVE命令的指令,请在Windows命令提示符下键入:

MOVE /?
Run Code Online (Sandbox Code Playgroud)


Gre*_*egg 8

robocopy 似乎是最通用的。查看帮助中的其他选项

robocopy /?
robocopy SRC DST /E /MOV
Run Code Online (Sandbox Code Playgroud)

  • 请注意,“/MOV”选项表示“移动文件,并在复制后将其从源中删除”,“/E”表示“复制子目录”。这有效地将所有文件移出源文件夹及其子文件夹,并在目标文件夹下重新创建文件夹结构,留下一个空的源文件夹和结构;如果目标文件夹尚不存在,它也会创建。Robocopy 非常强大,[这里是文档](https://technet.microsoft.com/en-us/library/cc733145(v=ws.11).aspx)。特别注意“/MOVE”选项(与上面的“/MOV”相反)。 (5认同)

San*_*uja 5

move /?在 Windows 和man mvUnix 系统上查找

  • `移动--帮助`?在 Windows 上?真的吗?你试过吗?:-) 我想你的意思是“移动/?”或“帮助移动”。 (2认同)