Computer Hope

Software => Computer programming => Topic started by: Whitebeard1 on May 16, 2013, 11:34:14 PM

Title: How to let the user select a path f a file and delete it in batch
Post by: Whitebeard1 on May 16, 2013, 11:34:14 PM
Hey im not sure how to let the user of a batch file select a file and delete it using batch. My computer keeps getting errors although i cannot find out what i programmed wrong. please help.
Title: Re: How to let the user select a path f a file and delete it in batch
Post by: Sidewinder on May 17, 2013, 03:52:07 PM
Quote
My computer keeps getting errors although i cannot find out what i programmed wrong. please help.

What errors? Syntax? Logic? You would do yourself a world of good if you posted what you have programmed.

How do you see this working? List the files in a folder and allowing the user to select one for deletion? Allowing the user to manually input the label of the file to be deleted?

 8)
Title: Re: How to let the user select a path f a file and delete it in batch
Post by: Whitebeard1 on May 28, 2013, 02:36:56 AM
Well, I want to let the user type in the path of the file and delete it.
Title: Re: How to let the user select a path f a file and delete it in batch
Post by: Sidewinder on May 28, 2013, 04:21:19 AM
Code: [Select]
@echo off
setlocal

set /p file=Enter File Name:
if exist %file% (
  echo del %file% && echo %file% has been deleted
) else (
  echo Incorrect File Name: %file%
)
 

I dislike writing destructive scripts, so this script performs a whatif scenario. When you're satisfied remove the first echo instruction from line 6.

 8)
Title: Re: How to let the user select a path f a file and delete it in batch
Post by: Whitebeard1 on May 29, 2013, 04:28:59 AM
Thanks alot sidewinder! I had found the mistake i made and i had successfully made this batch file that can dlete files. thx! :)