Link to home
Start Free TrialLog in
Avatar of csho
cshoFlag for United States of America

asked on

Robocopy to move subdirectores, without deleting root directory?

Is it possible to use robocopy to move all folders from C:\robo\from to C:\robo\to without deleting C:\robo\from?

Here's what I'm currently using...

robocopy C:\robo\from C:\robo\to /MOVE /E /R:2 /TEE /LOG+:C:\robo\movelog.txt
Avatar of flubbster
flubbster
Flag of United States of America image

Change MOVE to MOV

MOVE deletes files and directories from source.
MOV only deletes files from source
Avatar of ecsrd
ecsrd

This will work for you:

robocopy C:\robo\from C:\robo\to /MIR /R:2 /TEE /LOG+:C:\robo\movelog.txt

Basically, just remove the /MOVE and replace with /MIR.  The /MOVE command deletes the files and directories from the source!
Avatar of csho

ASKER

Thanks for the quick replies, although neither of those switches are doing what I need. When all is said and done, I want the C:\robo\from directory to be empty with all of the subdirectories moved to C:\robo\to

The MOV and MIR command are both leaving the subdirectory in C:\robo\from
err, you said you wanted the data moved "WITHOUT" deleting from the source:
"Is it possible to use robocopy to move all folders from C:\robo\from to C:\robo\to without deleting C:\robo\from?"

By default, there is no option to prevent robocopy from deleting the source directory if you use the MOVE command, and the MOV command will leave teh sub directories beneath the source directory.

What I would suggest is that (since it sounds like you're doing this often) you write a simple back script:

@echo off
robocopy C:\robo\from C:\robo\to /MOVE /E /R:2 /TEE /LOG+:C:\robo\movelog.txt
md C:\robo\from

That will move your data, and then re-create the from folder that is deleted, and also remove the sub-directories as you wanted.
argh, wtb edit button :D - back = batch*
Avatar of csho

ASKER

I had thought of that, but what is actually happening is the source directory (c:\robo\from) is "in use" so it is bombing out. The folder is "live" in that other processes could be looking for that folder so deleting it isn't an option even if it is only for a nanosecond.

I'm thinking robocopy isn't the tool I should be using for this, but I love how it handles things.
Yeah, robocopy has some limitations, it is still by far my favorite file copy utility that I aim to use as often as possible.  There are some instances that it can't handle though :S.
The reason it doesn't work is because the /MOVE command actually is invoking the "RD /S" command (remove all directories and files in the specified directory in addition to the directory itself.  Used to remove a directory tree." - and the limitation is the "RD" command, since there is no switch that just removes the sub-directories, not including the base directory...
ASKER CERTIFIED SOLUTION
Avatar of ecsrd
ecsrd

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of csho

ASKER

Genius! I've seen lots of other workarounds out there that were much much more complicated. Thanks!
Glad I could help!
Thanks, Great
I could not get this to work? Still shows the same error while using Robocopy V10.
Hi is it possible to move files from One folder to another Using Robocopy ,
I want to move only Rpt files  without overwriting if there exists  File with same name,  Also files from all subfolders in the directory also shoud moved.

I have done so far Below.

@echo off
    setlocal enableextensions enabledelayedexpansion

    rem configure directories
    set "source=E:\Source /S"
    set "target=E:\Destination"

    rem move non existing files to target
    call :doMove    

    rem if we still have files
    if exist "%source%\*.rpt" (

        rem generate a timestamp
        set timestamp=_%date:/=%_%time::=%
        set timestamp=!timestamp:,=!

        rem rename the remaining files with timestamp
        ren "%source%\*.rpt" "*.!timestamp!.rpt"

        rem and move the remainig files to target
        call :doMove
    )

    endlocal
    exit /b

:doMove
    robocopy "%source%" "%target%" "*.rpt" /fp /njh /njs /ndl /xc /xn /xo /xx /mov
    goto :EOF


Result
-----------
It moves all file from the path, But it does nt move files from the subfolders inside the path.
Please help me.