how to zip similar files using python?

Batch command to rename unzipped files using 7zip?

  • Hello! I receive a zip file daily. The zip file name changes every day to pc01012012.zip, pc01022012.zip, pc01032012.zip, etc... The zip contains many, many files, but I only need 2 of them. The 2 I need always have the same name - commsettle.txt and recon.txt. I unzip the files from the command line using the following code: 7z e F:\Tar\zips\pc*.zip -oF:\Tar\Reports commsettle* 7z e F:\Tar\zips\pc*.zip -oF:\Tar\Reports recon* So this extracts my 2 files, however, the names of the files are always the same, so I need to rename every time... I would like the batch file to automatically append the name of the zip file to the extract txt files. So the 2 extracted files would be named pc01012012_commsettle.txt and pc01012012_recon.txt Any ideas? Thanks! PS...I'm a batch command/scripting newbie

  • Answer:

    You can use a FOR command to identify the names of folders: SETLOCAL ENABLEDELAYEDEXPANSION FOR /f "tokens=*" %%a in ('dir /b f:\tar\zips\pc*.zip') do ( set FolderDate=%%~Na ::THEN, ALL YOU HAVE TO DO IS TAKE A SECTION OF THE FILENAME FROM 2, TO THE END OF THE NAME. set Folderdate=!folderdate:~2! ) ::now you can use the REN command to rename them with this new environment variable REN "(drive&path)\commsettle*.*" "(drive&path)\!folderdate!_commsettle.*"

Gary at Yahoo! Answers Visit the source

Was this solution helpful to you?

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.