1.

Solve : Mistaking In Batch?

Answer»

Hi Every 1
I m Mistaking Sumwhere in this batch

I Wanna Make A batch File to choose Either Yes Or no
Code: [SELECT]@echo off
color 0c
echo Type Either Yes Or No
set /p tp = :
IF %tp% equ yes GOTO ONE
IF %tp% equ no GOTO TWO
:ONE
cls
echo.
echo.
echo You Pressed Yes
echo.
echo.
pause
:TWO
cls
echo.
echo.
echo You Pressed no
echo.
echo.
pause
And Specially I wanna know After inserting Yes or no How 2 delete all Files in same folder I'm surprised a self described Guru such as yourself would need assistance with such a trivial matter. You have to write defensive code. No matter what the prompt says you never know what a user may actually type. Be a Boy Scout and be prepared.

Code: [Select]@echo off
color 0c
:tryagain
setlocal
set /p tp=Type Either Yes Or No:
IF /i .%tp% equ .yes GOTO ONE
IF /i .%tp% equ .no GOTO TWO
goto tryagain

:ONE
cls
echo.
echo.
echo You Pressed Yes
echo.
echo.
pause
goto :end

:TWO
cls
echo.
echo.
echo You Pressed no
echo.
echo.
pause

:end
endlocal

You GAVE no paths, so I leave it to you for the delete instruction. (del path\*.*). FYI: if the batch file path is the same as where the files to be deleted live, you'll end up deleting your own batch code.

Quote

And Specially I wanna know After inserting Yes or no How 2 delete all Files in same folder

If you're going to delete files whether the answer is yes or no, why bother asking?



>:(Hey SideWinder You Dont Know Something about Ur-Self



U R THE BEST!!!!! Thanks For The Help! I Wish You A Long Life

Thanx For The Help

Topic Closed Quote from: Sidewinder on January 29, 2010, 06:22:35 AM

If you're going to delete files whether the answer is yes or no, why bother asking?


Or in other threads "COMPUTER Experts" check to see if a certain file exists? If the file does not exist, the the OS will report that! Why check? If we try to create a file and it already exists, the OS will not allow it. So why go through the above procedure? A waste of time.Quote from: BillRichardson on January 29, 2010, 09:39:21 AM
Or in other threads "Computer Experts" check to see if a certain file exists? If the file does not exist, the the OS will report that! Why check? If we try to create a file and it already exists, the OS will not allow it. So why go through the above procedure? A waste of time.

checking to see if a file exists is a good idea if you plan to read from the file. If the file exists, you read the values from it; otherwise, you use the default values. If you don't check and INSTEAD blindly try and read, the values will not have the intended default values.

Or, in the case of an actual windows program, you'll crash when you try to use a file handle that doesn't exist (createfile will return -1 and getlastError() will be 2) and unless you check the handle (which is basically checking if the file exists, which as you've said we shouldn't be doing) then you'll try to read or write to a file handle of -1, which is not valid.Quote from: BillRichardson on January 29, 2010, 09:39:21 AM
Or in other threads "Computer Experts" check to see if a certain file exists? If the file does not exist, the the OS will report that! Why check? If we try to create a file and it already exists, the OS will not allow it. So why go through the above procedure? A waste of time.

Please explain more. The OP is deleting files, not creating them and is using a wildcard. The OP simply WANTS to empty a directory.

Quote from: the_mad_joker on January 29, 2010, 01:43:59 AM
And Specially I wanna know After inserting Yes or no How 2 delete all Files in same folder

Quote from: Sidewinder on January 29, 2010, 06:22:35 AM
If you're going to delete files whether the answer is yes or no, why bother asking?

The question remains. If the logic is to delete the files no matter what the response to the prompt is, why bother with the prompt at all?

PS. This is how threads turn into 5 page marathons that have nothing to do with anything.. The OP never mentioned creating files or reading from files.
I have a headache...


Discussion

No Comment Found