07-23-2023, 10:22 AM
I have a Directory with multiple `.tar` files which have multiple `.zip` files. The tree structure is somewhat of this sort:
testDirectory
-tarArchive.tar
-directory1
-zipArchive11.zip
abc.XML
1.TIF
2.TIF
...
-zipArchive12.zip
xyz.XML
a.TIF
b.CDX
...
.
.
.
-directory2
-zipArchive21.zip
...
-zipArchive22.zip
...
.
.
.
.
.
I need a single batch script to recursively extract only `.XML` from each `.zip` while maintaining the tree structure(first all `.zip` will be extracted from main `.tar` and then only `.XML` from each `.zip`). Additionally, the processed archives should be deleted afterwards.
I am able to achieve most of it with this code
for /R "C:\Users\frozenfyr\Desktop\test" %%I in ("*.zip", "*.tar") do (
"C:\Program Files\7-Zip\7z.exe" x -y -o"%%~dpI" "%%~fI" && del "%%~fI"
)
except 2 things:
1. I'm unable to extract `.XML` files only.
`"C:\Program Files\7-Zip\7z.exe" x -y -o"%%~dpI" "%%~fI"`**` "*.zip" -r`** will
not extract XML files and
`"C:\Program Files\7-Zip\7z.exe" x -y -o"%%~dpI" "%%~fI"`**` "*.XML" -r`**
doesn't(shouldn't) work because nothing will match in `.tar` file.
Is there a way to do something like
`"C:\Program Files\7-Zip\7z.exe" x -y -o"%%~dpI" "%%~fI"`**` "*.zip" "*.XML" -r`**
2. The main `.tar` file is not deleted after processing. I tried this
script on `.zip` files and it works(they are deleted after
processing).
I already tried a [powershell script][1] but I'm not very satisfied with it. I feel batch script is easy for me to handle. I even found a [post on SU][2] but it doesn't speak of multiple specific formats/files. I read [Command Line Version User's Guide][3] and considered [`-x` switch][4] but it's not useful.
I can't quote all the references here but I did go through a lot of SO and SU posts and Google was probably not my friend this time. I'm not sure whether SO or SU should be the place to ask this question, I found good references on both communities. I use SO more often so I'm here.
Please help me, this is driving me crazy..
[1]:
testDirectory
-tarArchive.tar
-directory1
-zipArchive11.zip
abc.XML
1.TIF
2.TIF
...
-zipArchive12.zip
xyz.XML
a.TIF
b.CDX
...
.
.
.
-directory2
-zipArchive21.zip
...
-zipArchive22.zip
...
.
.
.
.
.
I need a single batch script to recursively extract only `.XML` from each `.zip` while maintaining the tree structure(first all `.zip` will be extracted from main `.tar` and then only `.XML` from each `.zip`). Additionally, the processed archives should be deleted afterwards.
I am able to achieve most of it with this code
for /R "C:\Users\frozenfyr\Desktop\test" %%I in ("*.zip", "*.tar") do (
"C:\Program Files\7-Zip\7z.exe" x -y -o"%%~dpI" "%%~fI" && del "%%~fI"
)
except 2 things:
1. I'm unable to extract `.XML` files only.
`"C:\Program Files\7-Zip\7z.exe" x -y -o"%%~dpI" "%%~fI"`**` "*.zip" -r`** will
not extract XML files and
`"C:\Program Files\7-Zip\7z.exe" x -y -o"%%~dpI" "%%~fI"`**` "*.XML" -r`**
doesn't(shouldn't) work because nothing will match in `.tar` file.
Is there a way to do something like
`"C:\Program Files\7-Zip\7z.exe" x -y -o"%%~dpI" "%%~fI"`**` "*.zip" "*.XML" -r`**
2. The main `.tar` file is not deleted after processing. I tried this
script on `.zip` files and it works(they are deleted after
processing).
I already tried a [powershell script][1] but I'm not very satisfied with it. I feel batch script is easy for me to handle. I even found a [post on SU][2] but it doesn't speak of multiple specific formats/files. I read [Command Line Version User's Guide][3] and considered [`-x` switch][4] but it's not useful.
I can't quote all the references here but I did go through a lot of SO and SU posts and Google was probably not my friend this time. I'm not sure whether SO or SU should be the place to ask this question, I found good references on both communities. I use SO more often so I'm here.
Please help me, this is driving me crazy..
[1]:
[To see links please register here]
[2]:[To see links please register here]
[3]:[To see links please register here]
[4]:[To see links please register here]