Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Robocopy to move subdirectores, without deleting root directory?

Posted on 2009-04-08
14
Medium Priority
?
7,874 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

 
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 2000 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Configuring Remote Assistance for use with SCCM
By default Outlook 2016 displays only one time zone in the Calendar. The following article explains how to display two time zones in one calendar view.
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…
This Micro Tutorial will give you a basic overview of Windows DVD Burner through its features and interface. This will be demonstrated using Windows 7 operating system.

722 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