Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I am simply making an application now which shows you a list of files in a directory and then you can type in certain details and it will do the job for you. My problem is, whenever the code reaches the first "if" line, the damn thing just closes up. What's the problem? Here is my code so far :
@echo off
dir
echo file or folder ?
set /p source=
echo is it a folder or a file ?
set /p sourcetype=
echo delete or copy ?
set /p function=
if %function%=copy echo copy to where ?
set /p dest=
if %function%=delete set %function%=del
if %sourcetype%=file %function% %source%
if %sourcetype%=folder set %function%=rmdir /q /s
%function% "%source%"
if %function%=copy
if %sourcetype%=file
if not exist %dest% mkdir "%dest%"
else %function% "%source%" "%dest%"
if exist %dest% %function% "%source%" "%dest%"
else
if %sourcetype%=folder %function%=xcopy /e /h /r /k /x /y
%function% "%source%" "%dest%"
pause

You say "the damn thing just closes up." Do you mean you are running this batch file by double-clicking its name in Explorer? My tip is not to do that while you're developing the batch file. The window will close before you have time to read any error message that may appear.
If you run it from a Command Prompt, you will see the error message:
=copy was unexpected at this time.
This gives you a clue where the error is. Looks like a syntax error, so type IF /? to check how you are supposed to use the IF command.

To set a var, use SINGLE = like this:
set var=a
To test for equality, use DOUBLE = like this:
if %var%==a echo yes
=====================================
If at first you don't succeed, you're about average.M2

ah i have found out why - you were both right lol - the syntax is incorrect :P
i was doing this :
if something=something function
while i was supposed to be doing this :
if something==something function
i forgot the 2 ='s lol
thanks for ur help :)
batchlover
Batch is swift.... like a ninja! Be very afraid......

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |