Page 1 of 1

Remembering last entry

Posted: 20 Apr 2011 10:19
by 1bellb
Hi, I want to create a batch file, in this batch file I want to be able to type delete, then a message pops up saying Enter File Path:, now ths is where im stuck, when the person puts in c:/users/docs/myfile.txt, I want it to be deleted, the code I have is

@echo off
title Command Prompt
color a
A:
set input=
set /p input=input:
if %input%==delete goto b

:b
set input=
set /p input=Enter File Path:
goto A

but I need it to be able to rememeber what has being typed in before so I can add the code del *********** /f, with the ********* as what ever the file path typed in was

Thanks for reading
Ben

Re: Remembering last entry

Posted: 20 Apr 2011 12:47
by aGerman
Its the same like before. What you typed in is saved in variable %input% and the command line you need is
del /f "%input%"
I enclosed it in double quotes because of possible spaces in your entered path.
Have a look at this:

Code: Select all

@echo off
title Command Prompt
color a
:A
set "input="
set /p "input=input: "
if /i "%input%"=="delete" goto b
goto A

:b
set "input="
set /p "input=Enter File Path: "
if exist "%input%" (
  del /f "%input%"
  goto A
) else (
  echo File Not Found
  goto b
)


Regards
aGerman

Re: Remembering last entry

Posted: 21 Apr 2011 02:49
by 1bellb
Thanks a lot
This works perfectly
Cheers