Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rename extracted file based on zip file in Batch

I have multiple zip files with names such as 001.zip, 002.zip, 003.zip and have the potential to go up to 999.zip. Each zip file has exactly one text file. I would like to extract each zip file using Batch, and then rename the text file it extracted to the file name of the zip.

For example, if I extract 001.zip, I want the text file that gets extracted (all the text files that get extracted have different names) to be name 001.txt.

I at least am extracting all the files right now, but I am too unfamiliar with Batch, and am not sure if there is a simple way to do this?

cd test
echo     Decompressing zip4 data.
7z e *.zip
like image 784
Andrew Backes Avatar asked Dec 27 '22 20:12

Andrew Backes


1 Answers

for %F in (*.zip) do 7z e "%F" -so >"%~nF.txt" - provided there is only 1 file in in zip archive as you said (shown as if executed directly from command line, if used in batch use %%F)

like image 173
wmz Avatar answered Feb 16 '23 01:02

wmz