Solved

Robocopy to move subdirectores, without deleting root directory?

Posted on 2009-04-08
14
7,132 Views
Last Modified: 2016-10-04
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
0
Comment
Question by:csho
14 Comments
 
LVL 30

Expert Comment

by:flubbster
ID: 24099994
Change MOVE to MOV

MOVE deletes files and directories from source.
MOV only deletes files from source
0
 
LVL 11

Expert Comment

by:ecsrd
ID: 24100033
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!
0
 

Author Comment

by:csho
ID: 24100095
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
0
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 
LVL 11

Expert Comment

by:ecsrd
ID: 24100288
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.
0
 
LVL 11

Expert Comment

by:ecsrd
ID: 24100297
argh, wtb edit button :D - back = batch*
0
 

Author Comment

by:csho
ID: 24100347
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.
0
 
LVL 11

Expert Comment

by:ecsrd
ID: 24100378
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.
0
 
LVL 11

Expert Comment

by:ecsrd
ID: 24100413
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...
0
 
LVL 11

Accepted Solution

by:
ecsrd earned 500 total points
ID: 24100462
I have come up with a solution for you! - this will involve you placing a placeholder file in the directory that NEVER gets deleted (the base directory will only be removed if there are no files present in the directory):

Make a file called placeholder.txt in C:\robo\from

Then use the following script:

robocopy C:\robo\from C:\robo\to /MOVE /E /R:2 /XF "placeholder.txt" /TEE /LOG+:C:\robo\movelog.txt
0
 

Author Closing Comment

by:csho
ID: 31568152
Genius! I've seen lots of other workarounds out there that were much much more complicated. Thanks!
0
 
LVL 11

Expert Comment

by:ecsrd
ID: 24101092
Glad I could help!
0
 

Expert Comment

by:buchiag
ID: 36467712
Thanks, Great
0
 

Expert Comment

by:rexne1
ID: 40565573
I could not get this to work? Still shows the same error while using Robocopy V10.
0
 

Expert Comment

by:Mith Mithu
ID: 41828747
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.
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question