Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Make move rename conflicting files

Jun
223
0
Often when "flattening" directory structures - using [for /d %i in (*) move /hqs "%i\*.*" "%_cwd"], destination files with the same name get overwritten (which in most cases is ok).
At times however I'd like to preserve the then overwritten files, moving the "overwriting" file to the destination directory (as before) but renaming it at the same time (preferably appending the name of the source directory).
Clearly, a batch could be written to do this, but - for performance reasons - I'd like to avoid checking in advance for a file collision (hey, what about a try/catch ;-)
Hence I'd suggest a new switch (maybe also /R could be drilled open a bit?) to do this, indicating what should be done in case of a file name conflict:
/X[12]
1: Insert immediate parent folder name before the extension (default)
2: Insert a running number before the extension.

Example:

x.cpp
backup
x.cpp
old
x.cpp

... MOVE... /X? ... would result in a flat directory containing:

x.cpp
x (backup).cpp /X[1]
x (old).cpp /X[1]
x (1).cpp /X2
x (2).cpp /X2
 

Similar threads

Back
Top