I'm trying to create a simple batch file that will individually compress "rar" each file in the source directory. Naming of the rar files should be based on the date/time of file creation.
Having difficulties getting the names to reflect the accurate date/time. Currently all rar files created bear the same name. Think problem has to do with the use of nested FOR commands
Newbie here. Would appreciate help if possible.
setlocal
set _source=H:\Test
set _dest=J:\output
for /f "delims=/ tokens=1-3" %%a in ("%DATE:~4%") do (
for /f "delims=:. tokens=1-4" %%m in ("%TIME: =0%") do (
set _FILENAME=basename%%c%%b%%a%%m%%n%%o%%p
)
)
ECHO %_FILENAME%
for %%I in (%_source%\*.*) DO (
md "%_dest%\%%~nI"
"rar.exe" A -v50M -m0 -k -y -ep1 -r -t -hp[aabbcc] "%_dest%\%%~nI\%_FILENAME%.rar" "%_source%\%%~nxI"
phpar2.exe c -s640000 -r10 -l "%_dest%\%%~nI\%_FILENAME%.par2" "%_dest%\%%~nI\%_FILENAME%*.rar"
)
@echo off
setlocal
set "_source=H:\Test"
set "_dest=J:\output"
setlocal enableDelayedExpansion
for %%I in (%_source%\*.*) DO (
for /f "delims=/ tokens=1-3" %%a in ("%DATE:~4%") do (
for /f "delims=:. tokens=1-4" %%m in ("!TIME: =0!") do (
set _FILENAME=basename%%c%%b%%a%%m%%n%%o%%p
ECHO !_FILENAME!
)
)
md "%_dest%\%%~nI"
"rar.exe" A -v50M -m0 -k -y -ep1 -r -t -hp[aabbcc] "%_dest%\%%~nI\!_FILENAME!.rar" "%_source%\%%~nxI"
phpar2.exe c -s640000 -r10 -l "%_dest%\%%~nI\!_FILENAME!.par2" "%_dest%\%%~nI\!_FILENAME!*.rar"
)
endlocaL
endlocal
Is this what you want? You can nest the three loops but to use _FILENAME you'll need delayedExpansion.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With