General discussion

Locked

what is wrong with this script?

By gulik ·
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

This conversation is currently closed to new comments.

1 total post (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Try the highlighted changes

by NickNielsen In reply to what is wrong with this s ...

=====

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

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

if not exist %my_folder% goto error

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

Back to Windows Forum
1 total post (Page 1 of 1)  

Related Discussions

Related Forums