每个月我都会在一个特定的文件夹中有大量的文件(在许多子文件夹中)。我需要把它们全部移到不同的文件夹中。为了使它们的移动过程自动化,我在一个批处理文件中使用了robocopy。它运行良好,但运行需要小时。(它是许多GB)。
现在,如果我在Windows资源管理器中手动操作,打开所述文件夹,选择全部,右键拖动到目标文件夹,然后选择"移动到这里",它会立即移动。(Windows XP必须修剪和移植目录条目,而不需要再复制文件……是的,源和目标位于同一分区上。)
所以,问题是:有人知道我可以从批处理文件中运行一个程序,以这种即时的方式移动文件吗(需要移动整个子文件夹树)
您可以使用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:Userstest>mkdir to
C:Userstest>move from*.txt to
C:Userstestfrom1.txt
C:Userstestfrom2.txt
2 file(s) moved.
通过从@psmears指向正确方向的一个点,经过大量的谷歌搜索,我找到了(或a)解决方案:
@echo off
setlocal ENABLEDELAYEDEXPANSION
REM ** Change to source dir
L:
cd "L:BackupsSource"
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:BackupsSource"
for /f "usebackq delims=" %%d in (`"dir /ad/b/s | sort /R"`) do rd "%%d"