Solved

Robocopy to move subdirectores, without deleting root directory?

Posted on 2009-04-08
14
6,927 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
 
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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
Sometimes drives fill up and we don't know why.  If you don't understand the best way to use the tools available, you may end up being stumped as to why your drive says it's not full when you have no space left!  Here's how you can find out...
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…

943 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

Need Help in Real-Time?

Connect with top rated Experts

5 Experts available now in Live!

Get 1:1 Help Now