Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: How to let the user select a path f a file and delete it in batch  (Read 7612 times)

0 Members and 1 Guest are viewing this topic.

Whitebeard1

    Topic Starter


    Intermediate

    Thanked: 2
    • Computer: Specs
    • Experience: Familiar
    • OS: Mac OS
    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.
    Computers follow your orders, not your intentions.

    Sidewinder



      Guru

      Thanked: 139
    • Experience: Familiar
    • OS: Windows 10
    Re: How to let the user select a path f a file and delete it in batch
    « Reply #1 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)
    The true sign of intelligence is not knowledge but imagination.

    -- Albert Einstein

    Whitebeard1

      Topic Starter


      Intermediate

      Thanked: 2
      • Computer: Specs
      • Experience: Familiar
      • OS: Mac OS
      Re: How to let the user select a path f a file and delete it in batch
      « Reply #2 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.
      Computers follow your orders, not your intentions.

      Sidewinder



        Guru

        Thanked: 139
      • Experience: Familiar
      • OS: Windows 10
      Re: How to let the user select a path f a file and delete it in batch
      « Reply #3 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)
      « Last Edit: May 28, 2013, 05:05:59 AM by Sidewinder »
      The true sign of intelligence is not knowledge but imagination.

      -- Albert Einstein

      Whitebeard1

        Topic Starter


        Intermediate

        Thanked: 2
        • Computer: Specs
        • Experience: Familiar
        • OS: Mac OS
        Re: How to let the user select a path f a file and delete it in batch
        « Reply #4 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! :)
        Computers follow your orders, not your intentions.