Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

UNZIP all archives to separate subdirectory

I have a bunch of zip files in a directory. I would like to extract each archive to a subdirectory with the same name as the archive. Can the unzip command create directories? I tried creating the subdirectories first but I you can't have a file and directory with same name in the same directory. If I have a full path to a file, how do strip off just the file exension? For example, how would get rid of .txt from "C:\Program Files\JPSoft\TCMD22\readme.txt" to yield "C:\Program Files\JPSoft\TCMD22\readme"?

Code:
set filepath=E:\archive


for /r %filepath %x in (*.zip) (
    echo %x
    echo %x\%@filename["%x"]
    md "%x\%@filename["%x"]"
)
 
For example, how would get rid of .txt from "C:\Program Files\JPSoft\TCMD22\readme.txt" to yield "C:\Program Files\JPSoft\TCMD22\readme"?
Here's one way of doing it;
Code:
echo %@path[%@truename["%x"]]%@name[%@truename["%x"]]

Sample run;
Code:
c:\program files\jpsoft\tcmd27>echo %@path[%@truename[readme.txt]]%@name[%@truename[readme.txt]]
C:\Program Files\JPSoft\TCMD27\readme
Joe
 
Why would @truename be needed?
Code:
c:\program files\jpsoft\tcmd27>echo %@path[readme.txt]
ECHO is OFF

c:\program files\jpsoft\tcmd27>echo %@path[%@truename[[readme.txt]]
C:\Program Files\JPSoft\TCMD27\

Joe
 
He doesn't need the path if it's going to be the current directory (?). Untested ...

Code:
do z in *.zip
    md "%@name[%z]"
    unzip "%z" ".\%@name[%z]"
enddo
 
Then you get the extension, which the OP does not want.
Code:
c:\program files\jpsoft\tcmd27>echo %@full[readme.txt]
C:\Program Files\JPSoft\TCMD27\readme.txt

Joe
Why not

%@path[@full[readme.txt]]%@filename[%@full[readme.txt]]
 
Why not

%@path[@full[readme.txt]]%@filename[%@full[readme.txt]]
Code:
c:\program files\jpsoft\tcmd27>echo %@path[@full[readme.txt]]%@filename[%@full[readme.txt]]
readme.txt

Then you get the extension, which the OP does not want.

EDIT: You forgot the % in front of the first @full.

Code:
c:\program files\jpsoft\tcmd27>echo %@path[%@full[readme.txt]]%@filename[%@full[readme.txt]]
C:\Program Files\JPSoft\TCMD27\readme.txt

Joe
 
Here's what I wound up using. Worked perfectly

Code:
for /r %filepath %x in (*.cmp) (
    md  "%@path[%@truename["%x"]]%@name[%@truename["%x"]]"
    unzip "%x" "%@path[%@truename["%x"]]%@name[%@truename["%x"]]" PROGRAM.DBF
)
 

Similar threads

Back
Top