Remembering last entry

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
1bellb
Posts: 2
Joined: 20 Apr 2011 10:13

Remembering last entry

#1 Post by 1bellb » 20 Apr 2011 10:19

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

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Remembering last entry

#2 Post by aGerman » 20 Apr 2011 12:47

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

1bellb
Posts: 2
Joined: 20 Apr 2011 10:13

Re: Remembering last entry

#3 Post by 1bellb » 21 Apr 2011 02:49

Thanks a lot
This works perfectly
Cheers

Post Reply