Discussion Locked

what is wrong with this script?

0 helpful
1 reply
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

What is worng with this batch file ??? lets say i save that as comp.bat. after typing comp i have
Enter folder to compress: <- and i don't know what to type here :(:(:(
when i type C:\test - folder was not found
i'm sure that there is something missing or something wrong. can anyone help me? thanks for any suggestions :)

rem %1 name of attribute
echo %1
@echo off

set /P %my_folder%="Enter folder to compress: "

if exist %my_folder% goto %rar_file%
goto error

cd %my_folder%

rar.exe a %my_folder% -s

goto done

:error
echo folder was not found

:done

1 reply

by nicknielsen

=====

rem %1 name of attribute
echo %1
@echo off

set /P [b]my_folder[/b]="Enter folder to compress: "

[b]if not exist %my_folder% goto error[/b]

cd %my_folder%

rar.exe a %my_folder% -s

goto done

:error
echo folder was not found

:done

=====

Edit: Added rationale, corrected syntax

In the SET command, you are defining the VARIABLE, not calling the %VARIABLE%.

In the IF command:
a. I recommend using the "not exist" syntax in this case, primarily because it saves a couple lines of code. (I'm cheap with code. The fewer lines I can do it in, the better. It's a holdover from the single-sided, single-density days.)
b. 'error' and 'winrar' are labels and do not require the delimiters

This discussion is closed to new replies.