Windows 上的递归移动命令

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10155420/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 09:26:26  来源:igfitidea点击:

recursive move command on windows

windowscommand-line

提问by Daniel Mo?mondor

I need to do a .bat copy of a .sh, I don't know much Windows cmd. On Linux I could do

我需要做一个 .sh 的 .bat 副本,我不太了解 Windows cmd。在 Linux 上我可以做到

mv ...

or

或者

rsync -a SOURCE/ DEST/ --remove-sent-files --ignore-existing --whole-file

but Windows "move" can't do the same

但Windows“移动”不能做同样的事情

maybe there is a windows simple alternative, simpler and more performant than

也许有一个 Windows 简单的替代方案,比

for /R c:\sourceFolder\ %%G in (*) do ( move /Y "%%G" c:\destinationFolder\ )

Linux mv seems to update directories pointer, but the above Windows command will do hard stuff? I guess it's not a good idea for the big folders I need to frequently move

Linux mv 似乎更新目录指针,但是上面的 Windows 命令会做一些困难的事情吗?我想这对于我需要经常移动的大文件夹来说不是一个好主意

采纳答案by Raymond Chen

The movecommand can move directories as well as files.

move命令可以移动目录和文件。

cd /d C:\sourceFolder
rem move the files
for %%i in (*) do move "%%i" C:\destinationFolder
rem move the directories
for /d %%i in (*) do move "%%i" C:\destinationFolder

回答by Daniel Mo?mondor

Robocopy did wonders for me:

Robocopy 为我创造了奇迹:

 robocopy c:\cache c:\cache-2012 ?????-2012*.hash /S /MOV

I used it to move all files with certain mask out of c:\cacheand its numerous subdirectories.

我用它把所有带有特定掩码的文件移出了c:\cache它的众多子目录。

回答by Michael Schroeder

I know this is an old thread, but since it does not have a correct answer I figured I'd tie it off.

我知道这是一个旧线程,但由于它没有正确答案,我想我会把它绑起来。

The old DOS command to accomplish this is:

完成此操作的旧 DOS 命令是:

   move <source directory> <destination directory>

So in the OP question:

所以在 OP 问题中:

   move C:\sourceFolder c:\destinationFolder

The folder and everything in the folder (including sub-directories) will be moved.

文件夹和文件夹中的所有内容(包括子目录)都将被移动。

回答by janus

@echo off
setlocal
set DIR=
set OUTPUTDIR=C:\Documents and Settings\<username>\Desktop\sandbox1\output
for /R %DIR% %%a in (*.jpg) do xcopy "%%a" "%OUTPUTDIR%"

回答by Matt Hamende

XCOPY should do the trick, I use it it in batch files all the time

XCOPY 应该可以解决问题,我一直在批处理文件中使用它

something like, if you're just trying to target .sh files

类似的,如果你只是想定位 .sh 文件

XCOPY /E /H /Y /C "%SOURCEDIR%\*.sh" "%TARGETDIR%"  

Let me know if you have more questions

如果您有更多问题,请告诉我

回答by Rifat Hasan

For recursive move in windows, a simple movecommand is ok. Here is the example, I think it would be helpful.

对于 Windows 中的递归移动,一个简单的move命令就可以了。这是示例,我认为它会有所帮助。

move D:\Dbbackup\*.dmp* D:\Dbbackup\year\month\

Where .dmpis the extension of the file that would be moved to the location recursive folder Dbbackup , then year, then month.

.dmp将移动到位置递归文件夹 Dbbackup 的文件的扩展名在哪里,然后是年,然后是月。