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
Related Q & A:
- How to upload files using ajax?Best solution by Stack Overflow
- In Visual Studio 2012 or 2013, how can I register a DLL file on Windows 7 64-bit computer using a Custom Action command?Best solution by Stack Overflow
- What is the difference between internal command and external command in Linux?Best solution by answers.com
- What is the Command to Minimize Windows and Maximize Windows without using the mouse?Best solution by Yahoo! Answers
- What is the Command to Minimize Windows Maximize Windows switch Windows close Windows without using the mouse?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
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.