Reputation: 61
I have a series of file in a series of folders that need to be zipped individually.
C:\folder1\file1-1.txt
C:\folder1\file1-2.txt
C:\folder1\file1-3.txt
C:\folder2\file2-1.txt
C:\folder2\file2-2.txt
C:\folder2\file2-3.txt
C:\folder2\file2-4.txt
C:\folder3\file3-1.txt
C:\folder3\file3-2.txt
C:\folder3\file3-3.txt
C:\folder3\file3-4.txt
C:\folder3\file3-5.txt
I usee the below code to zip each folder, no problem:
for /d %%X in (fol*) do "c:\Program Files\7-Zip\7z.exe" a "%cd%\ZIPS\%%X.zip" "%%X"
And I'm left with 3 zip files in a directory "ZIPS" with the contents of each folder in their own ZIP, as is desired.
C:\ZIPS\folder1.zip
C:\ZIPS\folder2.zip
C:\ZIPS\folder3.zip
However within each file, I'm left with the folder as well as the files.
e.g. C:\ZIPS\folder1.zip\folder1\<files here>
What I'm after is the files being saved in the root of the directory:
e.g. C:\ZIPS\folder1.zip\<files here>
I've tried removing the "%%X" at the end of the line, however all that does is save all files in all directories for each folder.
Any assistance would be appreciated.
Upvotes: 0
Views: 2526
Reputation: 70941
Change to the folder where the files to compress are stored
for /d %%X in (fol*) do (
pushd "%%~fX" & (
"c:\Program Files\7-Zip\7z.exe" a "%cd%\ZIPS\%%~nX.zip" *
popd
)
)
Upvotes: 0