0

we have a program which unzips a file and store the unzippied files in a directory.

While unzipping, there may be a chance that the unzipped file come with the same name as we have unzipped as part of the other zipped file.

1.zip

test.log
test1.log

2.zip

test2.log
test1.log

I have a loop to look thru the *.zip file and then in the statement it unzips the file.

There it is failing, due to duplicate file.

I want to avoid replacing the file, I don't want to overwrite the file.

Can you please suggest some technique with which I can retain all the four files?

1
  • 1
    Is the "program" you're referring to a script ? If Yes, can you please include that in your question ? – Dhiwakar Ravikumar Apr 1 '15 at 6:44
0

The simple answer is to extract each archive to a separate directory thereby giving each archive a unique namespace (eg. 1/test.log, 1/test1.log, 2/test2.log, 2/test1.log).

If they must end up in the same place then you could instead prepend the archive name to each file name instead (eg. 1__test.log, 1__test1.log, 2__test2.log, 2__test1.log). This is definitely more effort though and there is still a very small chance that a name collision could occur if an archive name contains the separator character sequence (the __ part in my examples) which you've used.

0

Just use WINRAR and tick the boxes of all the context menu options in the setup.

Then you can select all the archives to be unzipped, right click on them and drag them to the folder you want them to be in and this will reveal the WinRar context menu.

You can then choose either to extract them all to the same directory, or each to their own named directory (named from the zip filename).

If you want them all in the same directory then choose 'Extract Here'.

WinRar automatically detects the duplicate filenames and offers you a series of options.

Just choose 'Rename all' and each subsequent duplicate will have a bracketed number appended to it's filename. eg (1), (2) etc.

1
  • Thanks for your comment, I need solution for command line. – Ashish Garg Apr 2 '15 at 0:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.