I have hundreds of zip and rar file inside a lot of subdirectories and I need to unzip them in folders named as file zip + date of zip file.
now I use this batch script :
FOR /D /r %%F in (".") DO (
pushd %CD%
cd %%F
FOR %%X in (\*.rar \*.zip) DO (
"C:\\Program Files\\7-zip\\7z.exe" e "%%X" -o"%%\~nX"\_"%%\~tX" -aou
)
popd
)
it functions but only under windows server 2019 and changing the format of the date to es. 01.01.23 otherwise it gives me an error because it can't create the folder ( under win 10 home it's impossible to use).
So I need to change the format of %%~tX into something as 01_01_23 so i can use under win 10 .
I improved the script like this :
FOR /D /r %%F in (".") DO (
pushd %CD%
cd %%F
FOR %%X in (\*.rar \*.zip) DO (
set "d=%%\~tX"
set "DD=%d:\~0,2%" & set "MM=%d:\~3,2%" & set "YY=%d:\~6,2%"
"C:\\Program Files\\7-zip\\7z.exe" e "%%X" -o"%%\~nX"\_"%DD%\_%MM%\_%YY%" -aou
)
popd
)
and it's ok
But if I add hour :
FOR /D /r %%F in (".") DO (
pushd %CD%
cd %%F
FOR %%X in (\*.rar \*.zip) DO (
set "d=%%\~tX"
set "DD=%d:\~0,2%" & set "MM=%d:\~3,2%" & set "YY=%d:\~6,2%"
set "HH=%d:\~9,6%"
"C:\\Program Files\\7-zip\\7z.exe" e "%%X" -o"%%\~nX"\_"%DD%\_%MM%\_%YY%.%HH%" -aou
)
popd
)
I create an undeletable directory. Why ?
Excuse me but during staging, Ground characters were added that I hadn't typed.
My latest revision is this:
setlocal EnableDelayedExpansion
FOR /D /r %%F in (".") DO (
pushd %CD%
cd %%F
FOR %%X in (*.rar *.zip) DO (
set "dt=%%~tX" & set "DD=%dt:~0,2%" & set "MM=%dt:~3,2%" & set "YY=%dt:~6,2%"
"C:\Program Files\7-zip\7z.exe" e "%%X" -o"%%~nX"."!DD!.!MM!.!YY!" -aou
)
popd
)
I launch the batch inside the directory that interests me (with all its subdirectories). And I have also this problem : variable %DD% , %MM%, %DD% remain the same despite having entered : setlocal EnableDelayedExpansion.
Thank you very much for everything. This is my first question. I learned a lot. with this version it's all ok for me.
FOR /D /r %%F in (".") DO (
pushd %CD%
cd %%F
FOR %%X in (*.rar *.zip) DO (
setlocal EnableDelayedExpansion
set "dt=%%~tX"
set "DD=!dt:~0,2!"
set "MM=!dt:~3,2!"
set "YY=!dt:~6,2!"
set "HH=!dt:~9,2!"
set "MI=!dt:~12,2!"
"C:\Program Files\7-zip\7z.exe" e "%%X" -o"%%~nX"_"!DD!_!MM!_!YY!_!HH!.!MI!" -aou
)
popd
)
P.S. : while trying, I made a syntax error and created folders like "example_.." that I can't delete even with paid software.And if i copy a file inside automatically windows create a new folder with the same name minus "." es: "pippo_.." became "pippo_" with the file inside, and I can delete this new directory but not the first named "pippo_.." And with many file folders I get : Maximum recursion level of setlocal reached, but this does not affect the final result.