Robocopy: Copy file, and if an identical file name exists in destination, keep BOTH - powershell

I've got this line of code using Robocopy:
Robocopy C:\Autopilot_Export \\Zapp\pc\PLI\Hash_Exports Autopilot_CSV.csv
I will have multiple computers networked into this server running this same script and they'll be copying different CSVs under the same CSV name "Autopilot_CSV".
Is there a way to have Robocopy behave similarly to how Windows 10 does when you copy an identical file to a directory and hit "Keep Both" when prompted? So it would end up naming them Autopilot_CSV.csv, Autopilot_CSV(1).csv, Autopilot_CSV(2).csv, Autopilot_CSV(3).csv, and so on...
I've looked over the Robocopy documentation and found the /XN /XO /XE options, but they appear to all be referencing timestamps, differing sizes, older, and newer files. The timestamps and sizes of these files are going to all be different, however, the file names will be the same.
Is there a way to do this?
Thanks!

Related

How to perform two ROBOCOPY statements from one source folder to two destination folders in one batch file?

I have an interesting situation where I'd like to move some files from directory X to directory Y, but in order to MOVE the files without deleting the source folder, I created a log statement in said folder. A very simple version of what I'm doing is this:
robocopy
"C:\Desktop\Origin" "C:\Desktop\Destination"
/e /move /XF "C:\Desktop\Origin\test.log"
/log:"C:\Desktop\Origin\test.log"
This results in the moving of all files in "Origin" directory to "Destination" directory, and doesn't get rid of the "Origin" directory, as the "/e /move" flags normally would. Now, if I didn't want that log file, I could simply add this line to the code:
del "C:\Desktop\Origin\test.log"
But, I actually do want to keep this log file. I just want it somewhere else. So what I've been trying to do is to move it to directory Z with "/e /mov" or even just "/s" and then the delete. For example:
robocopy
"C:\Desktop\Origin" "C:\Desktop\Destination"
/e /move /XF "C:\Desktop\Origin\test.log"
/log:"C:\Desktop\Origin\test.log"
robocopy
"C:\Desktop\Origin" "C:\Desktop\Destination 2"
/s
del "C:\Desktop\Origin\test.log"
But after trying multiple times, with multiple little variations, nothing seems to happen. The first robocopy happens, but the second doesn't seem to happen at all. It seems like multiple robocopy statements can run in one batch file (which is what I want) but perhaps not from the same source directory. Does anyone know why this is the case and also how I can achieve my stated goal? Thanks!
Thanks to the suggestion of Ken White, I found a solution to this. If you use MOVE.EXE, it works just as expected.
robocopy
"C:\Desktop\Origin" "C:\Desktop\Destination"
/e /move /XF "C:\Desktop\Origin\test.log"
/log:"C:\Desktop\Origin\test.log"
move
"C:\Desktop\Origin\test.log" "C:\Desktop\Destination 2"
One thing to note is that you can't use /LOG+: with this method, since you'd be writing the log file to a location where no log file exists, since it had been moved previously to "Destination 2". However, even the normal log files include the *EXTRA files already in the directory.

Robocopy not excluding changed files

I am copying a full directory over and am trying to exclude changed files. Note that I am doing this in Powershell.
robocopy "D:\Projects\Publishes\css" "D:\Projects\robocopy test\css" /xc
However my changed files at destination are being over-written. I can't use exclude older or newer files by the nature of my situation so these are out.
NOTE:
On the MSDN page it says /xct to exclude changed files but if I do this I get the following error:
ERROR : Invalid Parameter #3 : "/xct"
From other examples I've seen /xc so that is what I'm using here.
I translate your requirement as:
Some files on the destination directory have been changed. Don't replace those.
I think what you are looking for is the /XO flag
robocopy "D:\Projects\Publishes\css" "D:\Projects\robocopy test\css" /xo /e
This translates to
Do not overwrite newer files on the destination directory
Your /xn flag actually means
Do not copy newer files from the source directory
Sightly different.

copy files not directory structure. paths longer than 255characters

I need to flatten a directory structure. I have a very large directory with 6000+ directories and 40000+ files. Some are 12 levels deep and have files in them. The paths exceed 255 character limits and if you add the file names, some are 400 characters +. copy and xcopy will not work for this task. I tried a For /R loop with copy and xcopy and they fail at going beyond 255 character paths. I receive a file not found error.
I know that robocopy is good for 36000 characters, so it seems to be the only option. is there anyway to script this in powershell or batch, vb? every variation I have tried copies the directory structure along with the files.
any help is appreciated.

Is there any batch command to move files and delete empty sub folders

Anyone know of a simple batch command to move files and delete empty sub folders? Just got a new external and when I copied everything over it resulted in something like this. F:\Music\John Denver\John Denver\files1-10 F:\Music\TheBeatles\TheBeatles\files1-10 and so on, for say, 350+ folders. I don't want to waste that much time manually moving them up one folder and deleting sub folders... Not all files are same file type, and not all folders are music. Some folders have other sub folders that I want to keep (mostly for music files, such as artist\album\files) Is there a way to do this instead of the old fashioned way? Any help is appreciated.
You can use ROBOCOPY.
ROBOCOPY source destination /S /MOVE
/S flag is used to exclude empty subfolders.
ROBOCOPY "F:\Music\John Denver\John Denver\files1-10" "F:\Music\TheBeatles\TheBeatles\files1-10" /S /MOVE

How can I remove a Windows directory without following junction points?

I have a Perl script that needs to delete a directory with all its contents.
Sometimes this directory contains a junction point into another directory. If I rmtree() naively, the rmtree() call will also delete all the files inside the target folder of the junction. I'm looking for a way to not do that, and instead just remove the junction.
Non Perl solutions would also be appreciated.
I just typed "junction point" into Google and found my way to
http://en.wikipedia.org/wiki/NTFS_junction_point
Command Prompt (cmd.exe)
The dir
command in Windows 2000 or later
recognizes junction points, displaying
instead of in
directory listings (use dir with the
/A or /AL command-line switch).
Any
commands that would normally affect
files inside a normal directory will
act the same here. Thus the command
del myjunction should not be used —
this will just delete all the files in
the targeted directory.
The commands
rmdir and move work fine with
junctions, with the caveat that move
won't let the junction move to another
volume (as opposed to Windows
Explorer, as mentioned above.)
The
rmdir command is safe in that it only
deletes the junction point, not the
targeted files. Whilst walking through
the directory with the command line
interface, files can be deleted, but
unlike explorer, directories can also
be deleted (using rmdir /s dirname for
example.)
Using the linkd command with
the /d switch is a safe way to delete
junction points.
From what I can see you can, for example, use dir and grep the output for <JUNCTION> or use the Windows rmdir. I think you can use either of these from Perl via system.
To find out where are the reparse points (or "junction points", if you will):
dir /a:l /b > myjunctions.txt
Will show all reparse points in the current directory. You can add /s, but beware that reparse points inside reparse points will be listed as well.
Suppose myjunctions.txt contains the line x:\subdir\foo. To remove it, you issue
fsutil reparsepoint "x:\subdir\foo"
And voilá! Your junction point is gone, and the original directory is untouched!
FastCopy utility does this: http://ipmsg.org/tools/fastcopy.html.en
I am using this program for copying or deleting folders that may contain junctions as subfolders so that the junction targets remain untouched. The junction points are properly copied while copying, even when the target drive is different.
Windows Explorer at least in Windows 7 Ultimate works also as wanted while deleting - junction targets remain intact.
But copying folders that contain junctions as subfolders in Explorer still does not work as intended - it actually does something that I cannot yet perhaps quite entirely describe: the junction folders seem to be copied as normal folders, but their content is empty.