首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用命令行将所有文件从一个文件夹移动到另一个文件夹?

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

Stack Overflow用户
提问于 2011-01-20 11:10:52
回答 9查看 335.5K关注 0票数 61

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

我想从一个批处理文件中执行此操作。

EN

回答 9

Stack Overflow用户

回答已采纳

发布于 2011-01-20 11:34:21

您可以使用move来实现这一点。来自help move的文档指出:

代码语言:javascript
运行
复制
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.

参见下面的文字记录,其中的示例最初显示qq1qq2目录分别具有三个文件和没有文件。然后,我们执行move,我们发现这三个文件已经像预期的那样从qq1移动到qq2

代码语言:javascript
运行
复制
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
代码语言:javascript
运行
复制
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
代码语言:javascript
运行
复制
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
票数 63
EN

Stack Overflow用户

发布于 2011-01-20 11:56:05

代码语言:javascript
运行
复制
move c:\sourcefolder c:\targetfolder

都会起作用,但是你最终会得到这样的结构:

代码语言:javascript
运行
复制
c:\targetfolder\sourcefolder\[all the subfolders & files]

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

代码语言:javascript
运行
复制
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
票数 36
EN

Stack Overflow用户

发布于 2011-01-20 11:33:38

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

代码语言:javascript
运行
复制
MOVE c:\originalfolder\* c:\destinationfolder

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

要查找MOVE命令的说明,请在windows命令提示符下键入以下命令:

代码语言:javascript
运行
复制
MOVE /?
票数 25
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4743094

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档