• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

winrar command-line help

thegodsend

Junior Member
I need help making a .bat. i have some experience withe programming/cmd but not very extensive. I need help making it so that if theres an error upzipping it skips that .zip. I also need it logging everything that's possible to log. From there i would like errors to be in red (maybe not possible).

Here is what i have. unziping of the folder and overwriting if needed (-o+) and deleting the .zip when its finished.
Code:
@echo off
REM *** Pizza Place ***

REM *** Pizza Place - 21st ***
"C:\Program Files\WinRAR\winrar.exe" x -o+ D:\Pizza Place\21st\RMFTP*.zip *.* D:\Pizza Place\21st\ 
del D:\Pizza Place\21st\RMFTP*.zip
 
Last edited:
How's this, for starters? I haven't tried it and my batch file syntax is probably very rusty, but you should be able to get something like this to work:
Code:
@echo off
for %%i in ("D:\Pizza Place\21st\RMFTP*.zip") do "C:\Program Files\WinRAR\winrar.exe" x -o+ "%%i" *.* D:\Pizza Place\21st\ && del "%%i"
for %%i in ("D:\Pizza Place\21st\RMFTP*.zip") do echo An error occurred extracting %%i >> "D:\Pizza Place\21st\extraction_log.txt"
 
How's this, for starters? I haven't tried it and my batch file syntax is probably very rusty, but you should be able to get something like this to work:
Code:
@echo off
for %%i in ("D:\Pizza Place\21st\RMFTP*.zip") do "C:\Program Files\WinRAR\winrar.exe" x -o+ "%%i" *.* D:\Pizza Place\21st\ && del "%%i"
for %%i in ("D:\Pizza Place\21st\RMFTP*.zip") do echo An error occurred extracting %%i >> "D:\Pizza Place\21st\extraction_log.txt"

thank you so much. this is almost exactly what i wanted in the first post. if you would amuse me, i would like to try and understand this.

Code:
for %%i in
creates a file in a destination folder. then if the extraction takes place, it deletes that file. if it fails to extract the .zip then it echos said error then appends that to a .txt. im slightly confused to how the .zip is deleted at the same time with 1 del command. unless the "for %%i in" attaches its self to the .zip?

so if i wanted to make a message saying it has completed i would do the same thing but with a different variable?

this is a batch going on an FTP server automatically backing up databases so these commands will be repeated A LOT. i belive i have found a way to time stamp the log so thats helpful.

sorry, last time iv done something like this was 4-5years ago.
 
Last edited:
"for %%i in (X) do ..." means that for every file matching X, the stuff after the "do" is run, with the current match stored in the variable %%i. Batch file for loops are a huge kluge because it's either hard or impossible to do a set of commands on separate lines. But "&&" gets the return value of the command before it, and if it's "0" (conventionally meaning no error occurred), it runs the command after it.

The second for loop operates on any files remaining after the extractions and deletions, which should be no files if the extractions were successful. If you want a success message for each extraction, try adding "&&" followed by an echo at the end of the first for line. If you want a success message that there were no errors, try something like 'IF NOT EXIST "D:\Pizza Place\21st\RMFTP*.zip" echo Success'.
 
"'IF NOT EXIST "D:\Pizza Place\21st\RMFTP*.zip" echo Success'.
if not exist *surprised face*.. got a kick out of that.

any who..

so the fail/success message logs seem to be working properly now. im having trouble figuring out how to log the directory of the file that was a success though. also, do u know about adding color to text in a log? so that the errors come out more clear. i looked around and it seems you need to use a 3rd party software or tool. not agents it but sense u can change the color of text in cmd i would think there's a way to log it in a different color.

Code:
@echo off

REM *** Pizza Place - 21st ***

REM ** Extraction **
for %%i in ("C:\FTP\Pizza Place\21st\RMFTP*.zip") do "C:\Program Files\WinRAR\winrar.exe" x -o+ "%%i" *.* "C:\FTP\Pizza Place\21st\" && del "%%i"

REM ** Error Log **
for %%i in ("C:\FTP\Pizza Place\21st\RMFTP*.zip") do echo An error occurred extracting %%i >> "C:\FTP\! Logs\%DATE:~-4%-%DATE:~4,2%-%DATE:~7,2%.log"

REM ** Success Log **
IF NOT EXIST "C:\FTP\Pizza Place\21st\RMFTP*.zip" (echo Success) >> "C:\FTP\! Logs\%DATE:~-4%-%DATE:~4,2%-%DATE:~7,2%.log"
 
Back
Top