-1

每个月我在特定文件夹中都有大量文件(在许多子文件夹中)。我需要将它们全部移动到不同的文件夹中。为了使移动它们的过程自动化,我在批处理文件中使用了 robocopy。它工作正常,但需要HOURS才能运行。(很多很多 GB)。

现在,如果我在 Windows 资源管理器中手动执行此操作,打开所述文件夹,选择所有文件夹,然后右键拖动到目标文件夹,然后选择“移至此处”,它会立即移动。(Windows XP 必须修剪和移植目录条目,而无需制作文件的第二份副本。...是的,源和目标位于同一分区上。)

所以,问题是:有谁知道我可以从批处理文件运行的程序以这种瞬时方式移动文件? (需要移动整个子文件夹树)

4

2 回答 2

1

您可以MOVE为此使用:

C:\>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.

例如:

C:\Users\test>mkdir to
C:\Users\test>move from\*.txt to
C:\Users\test\from\1.txt
C:\Users\test\from\2.txt
        2 file(s) moved.
于 2015-04-01T19:18:07.750 回答
0

通过@psmears 的正确方向和大量谷歌搜索,我找到了(或一个)解决方案:

@echo off

setlocal ENABLEDELAYEDEXPANSION


REM  ** Change to source dir

L:
cd "L:\Backups\Source"



REM  ** Move files recursively

for /R %%G in (.) do (

set mydir=%%G
set mynewdir=!mydir:~18!

md "L:\DEST\!mynewdir!"
cd "L:\DEST\!mynewdir!"
move "%%G\*.*" .

)



REM  ** Remove now-empty sub-dir structure inside source

L:
cd "L:\Backups\Source"

for /f "usebackq delims=" %%d in (`"dir /ad/b/s | sort /R"`) do rd "%%d"
于 2015-04-01T21:48:13.343 回答