I would like to use 7ZIP to extract files with specific extensions only, and then rename one of them accordingly.
Also, i must do this using a batch script (.bat) - No powershell or other methods.
I currently set up the following script, on a bat file:
@echo off
REM Force UTF-8 to fix some output problems
chcp 65001 > nul
REM Six columns, space delimited
for /f "tokens=6 delims= " %%A in ('"C:\Tools\7za.exe" l VPN.zip -ba -r *\*.ovpn') do (
"C:\Tools\7za.exe" e VPN.zip -ba -r %%A > Test.ovpn
)
PAUSE
Output:
It exracts two files.
One is the archive itself (Archive...ovpn) The second one is the one i renamed (Test.ovpn) The second archive, instead of being the actual renamed archive, contains 7Zip logs... Log is below.
Processing archive: VPN.zip
Extracting folder_name\Original_archive.ovpn
Everything is Ok
Size: 411 Compressed: 5800
It lists the files in my zipped archive...
What i want to achieve is:
Extract files only to a folder called "VPN", and not folder_name.
If the files contains the extension .ovpn, rename that file to "Test.ovpn"
I am very sorry if this question seems silly. I am quite new on batch scripting field and here is the only place where i can get some help...
Thank you for anyone that helps me.
Edit: I updated the questions with the codes i'm using, since on comments they said this question was'nt clear enough...
CodePudding user response:
I solved it by using the following code:
REM Extract files in archive
for %%f in (VPN.zip) do (
"C:\Tools\7za.exe" e "%%f" -ba -y -so -r *\*.ovpn 1>C:\VPN\VPN.ovpn 2>nul
"C:\Tools\7za.exe" e "%%f" -ba -y -r *\*.p12 -oC:\VPN >nul
"C:\Tools\7za.exe" e "%%f" -ba -y -r *\*.key -oC:\VPN >nul
) >nul