UNZIP all archives to separate subdirectory

Sep 6, 2020
9
0
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
 
May 20, 2008
10,987
86
Syracuse, NY, USA
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
 
Apr 2, 2011
1,350
6
53
North Carolina, USA
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
 
Sep 6, 2020
9
0
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
)
 
Thread starter Similar threads Forum Replies Date
C Support 2
Joe Caverly Support 3
JohnQSmith Support 2
D Support 3
D Support 0