需要移动文件而不复制然后删除它们的批处理程序
Need batch program that moves files without copying then deleting them
每个月我的特定文件夹中都有大量文件(在许多子文件夹中)。我需要将它们全部移动到不同的文件夹中。为了使移动它们的过程自动化,我在批处理文件中使用了 robocopy。它工作正常,但需要 HOURS 到 运行。 (很多很多 GB)。
现在,如果我在 Windows Explorer 中手动执行此操作,打开所述文件夹,全选,然后右键拖动到目标文件夹,然后选择 "Move Here",它会移动 立即。 (Windows XP 必须 p运行ing 和嫁接目录条目,而无需制作文件的第二个副本。...是的,源和目标位于同一分区上。)
所以,问题是:有人知道我可以从批处理文件 运行 以这种即时方式移动文件的程序吗? (需要移动整个子文件夹树)
您可以为此使用 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.txt
C:\Users\test\from.txt
2 file(s) moved.
@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"
每个月我的特定文件夹中都有大量文件(在许多子文件夹中)。我需要将它们全部移动到不同的文件夹中。为了使移动它们的过程自动化,我在批处理文件中使用了 robocopy。它工作正常,但需要 HOURS 到 运行。 (很多很多 GB)。
现在,如果我在 Windows Explorer 中手动执行此操作,打开所述文件夹,全选,然后右键拖动到目标文件夹,然后选择 "Move Here",它会移动 立即。 (Windows XP 必须 p运行ing 和嫁接目录条目,而无需制作文件的第二个副本。...是的,源和目标位于同一分区上。)
所以,问题是:有人知道我可以从批处理文件 运行 以这种即时方式移动文件的程序吗? (需要移动整个子文件夹树)
您可以为此使用 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.txt
C:\Users\test\from.txt
2 file(s) moved.
@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"