1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Make move rename conflicting files

Discussion in 'Suggestions' started by nickles, Jan 10, 2013.

  1. nickles

    Joined:
    Jun 24, 2008
    Messages:
    220
    Likes Received:
    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
     

Share This Page