Good day!

I have a question about robocopy:

I wrote a script lately for move files and folders into another specific folder.
More precisely the script searches files and folders which are older than 30 days and move them to another folder.
Exemplary:

I:\Examplefolder\

1-30 days Folder A Folder B Folder C

In the folders are many files. The folder 1-30 days is the destination of the script. Files and folders which are older than 30 days should be moves to 1-30 days (/move - so deleting at the source after).

To put it simple I start testing it under easy conditions without /MINAGE and just 3 folders with empty files. I use the following robocopy command:

robocopy.exe I:\Examplefolder “I:\Examplefolder\1-30 Days” /E /MOVE /XD “I:\Examplefolder\1-30 Days”

Now we come to the core, my problem:
On the first run the script does not move the folders into 1-30 Days. Just the files and it “copies” the folders like mirroring but delete the files on the source (like I want to).
The empty folders remain. Just on the second run with empty folders now it moves the folders too…
What is wrong with my script?

I hope I could make it understandable :slight_smile:
Thanks for your help!

6 Spice ups

I think that the directory’s are still in use when robocopy wants to remove them. You could try a retry /r:3 /w (wait time is 30 seconds by default).

Also, is the log options telling you something?

robocopy.exe I:\Examplefolder “I:\Examplefolder\1-30 Days” /E /MOVE /XD “I:\Examplefolder\1-30 Days”

How about adding the “/S” switch to get subfolders?

You may also want to look at “/COPYALL” -

That’s what the /E switch does

/S :: copy Subdirectories, but not empty ones.

/E :: copy subdirectories, including Empty ones.

Unfortunatly the /S-Switch did not change a thing. I tested it long-termed with different options and the /S and /E Switch do the same…

I made a simple Enviroment with 3 Folders and 4 Files and with both switches I get the same result… On the first run the script moves the files and let the empty folders back.

The /COPYALL is not what I need. I want to move the files and folders not just copy.

I tested another thing:

When I create an empty folder in an empty folder in an empty folder and start the script it JUST moves the folder on the deepest path. Like a 1-time check.

For example:

test\test\test the script moves the latest test folder, ends and leave the rest untouched…

I’ve got it!

I don’t know why but if I don’t use /MT:N in this command it works perfectly and move all folders, even empty ones.

I can’t tell you why but that solves my problem :slight_smile:

/MT did not solve your issue… why would you believe specifying the copy as multi-threaded would solve it?

As I mentioned above , the /E switch’s purpose is to “copy subdirectories, including Empty ones.”

Perhaps the help function of RoboCopy should be of some use here:

robocopy /? 

as /COPYALL has nothing to do with copying files and folders and everything to do with file attributes.

Interesting that you say my problem is not solved, when I say MY problem is solved…

You don’t get it I guess. I used the /E-Swtich. I tested it many times with the Switches. No matter what combination I used neither solved my problem. The empty folders always remains.

So I tried to drop other options and without the /MT:N option it worked. All files and folders moved on the first try. I transferred this now to my real script and it worked. I can’t tell you why but It does what it’s written for.

Maybe I did not make myself clear but that is what I expected.

rodjunior9 wrote:

Interesting that you say my problem is not solved, when I say MY problem is solved…

I didn’t say your problem isn’t fixed, but that using /MT would not fix it.

  • If you were using /MT from the beginning, you left it out of your OP, and if you weren’t including it from the beginning, then /MT was not the initial cause of your issue, but an additional issue that was created by trying random switches without understanding what those switches do.
  • /MT would cause empty folders to remain because RoboCopy would be attempting to move those folders at the same time files within those folders are being moved.

Well most of the things you said are true and good, there are a few things that are wrong.

I’m clear a /mt:n switch can’t fix a problem that’s not related to it. I’m sure of that, but a low percentage chance does not mean its impossible. Particulary we do not know exactly how robocopy works.

I read the manual carefully and I am sure what every switch does I use or used to now. With “trying random switches” I just mean, that I try switch combinations with brain.

It must be a very rare special case that my normal pc with normal processes started change from one minute to the other… Even on my live enviroment with complex processes and other things related it works. Seems like witchcraft or something.

Well nevermind it works. Thanks for your help!

Have a nice day!