user1125394
user1125394

Reputation:

recursive move command on windows

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

mv ...

or

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

but Windows "move" can't do the same

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

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

Upvotes: 13

Views: 51153

Answers (7)

Eric Cloninger
Eric Cloninger

Reputation: 2260

I don't have a one liner, but here's what I did using CMD and Notepad++...

  1. F:> DIR /S /B > moveit.bat This gives you all your file names

  2. Use Notepad++ to edit the bat file Replace with Regular Expression, search for ^(.+?)$ and replace with MOVE "$1" %DESTDIR% Save, exit

  3. Execute your batch file.

Upvotes: 0

Michael Schroeder
Michael Schroeder

Reputation: 21

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:

   move <source directory> <destination directory>

So in the OP question:

   move C:\sourceFolder c:\destinationFolder

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

Upvotes: 2

janus
janus

Reputation: 1

@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%"

Upvotes: 0

Rifat Hasan
Rifat Hasan

Reputation: 5

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

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

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

Upvotes: -2

Daniel Mošmondor
Daniel Mošmondor

Reputation: 19956

Robocopy did wonders for me:

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

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

Upvotes: 19

Raymond Chen
Raymond Chen

Reputation: 45173

The move command can move directories as well as files.

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

Upvotes: 12

Matt Hamende
Matt Hamende

Reputation: 139

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

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

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

Let me know if you have more questions

Upvotes: 1

Related Questions