How to delete files using batch files on Windows

Table of contents:

How to delete files using batch files on Windows
How to delete files using batch files on Windows
Anonim

Want to delete files in a folder with one click? Are you an application developer who wants to make sure that his program can easily delete any file? Then this article is for you. Follow the steps in this article to get what you want.

Before you start

  1. Open the Run dialog box, type Explorer and press Enter. To open the Run dialog box, press Win + R on your keyboard at the same time.
  2. Press alt = "Image" on your keyboard (the explorer window should be active).
  3. Click on Tools> Folder Options.
  4. When the "Folder Options" window appears on the screen, go to the "View" tab.
  5. Uncheck the option "Hide extensions for registered file types", if it is there.
  6. Click OK.

    Steps

    Delete a File in Microsoft Windows Using Batch Files Step 1
    Delete a File in Microsoft Windows Using Batch Files Step 1

    Step 1. Open Notepad

    To do this, click on Start> All Programs> Accessories> Notepad.

    Delete a File in Microsoft Windows Using Batch Files Step 2
    Delete a File in Microsoft Windows Using Batch Files Step 2

    Step 2. Enter "cd" (without quotes) into Notepad

    Delete a File in Microsoft Windows Using Batch Files Step 3
    Delete a File in Microsoft Windows Using Batch Files Step 3

    Step 3. Find the folder or file you want to delete, then right-click on it and select Properties

    Delete a File in Microsoft Windows Using Batch Files Step 4
    Delete a File in Microsoft Windows Using Batch Files Step 4

    Step 4. Copy the data from the "Location" line

    Delete a File in Microsoft Windows Using Batch Files Step 5
    Delete a File in Microsoft Windows Using Batch Files Step 5

    Step 5. Go back to Notepad, put one space after "cd" and paste the copied information, enclosing it in quotation marks

    For example, if you copied "C: \ Users \ Administrator", then the notepad will say "C: \ Users \ Administrator" (with quotes).

    If you want to delete files from a specific folder, but the file is not there, start from the third step and enter its location

    Delete a File in Microsoft Windows Using Batch Files Step 6
    Delete a File in Microsoft Windows Using Batch Files Step 6

    Step 6. Press Enter on your keyboard to move to another line

    Delete a File in Microsoft Windows Using Batch Files Step 7
    Delete a File in Microsoft Windows Using Batch Files Step 7

    Step 7. Enter "del" (without quotes) in a new line of Notepad

    Delete a File in Microsoft Windows Using Batch Files Step 8
    Delete a File in Microsoft Windows Using Batch Files Step 8

    Step 8. Put a space and enter the name of the folder or file with the extension (if it has one) that you want to delete, enclosing it in quotation marks

    For example, if you want to delete the "Delete me" folder, then you need to enter the following: del "Delete me". If you want to delete the music.wav file, enter del "music.wav".

    Delete a File in Microsoft Windows Using Batch Files Step 9
    Delete a File in Microsoft Windows Using Batch Files Step 9

    Step 9. At the top of the Notepad, click File> Save As

    Delete a File in Microsoft Windows Using Batch Files Step 10
    Delete a File in Microsoft Windows Using Batch Files Step 10

    Step 10. In the "Save" window, in the "File Type:" line, select "All Files"

    Delete a File in Microsoft Windows Using Batch Files Step 11
    Delete a File in Microsoft Windows Using Batch Files Step 11

    Step 11. In the "File name:" field, enter "your_name.bat" (without the quotes)

    Replace "your_name" with the name of the file.

    Delete a File in Microsoft Windows Using Batch Files Step 12
    Delete a File in Microsoft Windows Using Batch Files Step 12

    Step 12. Click "Save"

    Delete a File in Microsoft Windows Using Batch Files Step 13
    Delete a File in Microsoft Windows Using Batch Files Step 13

    Step 13. Find the new file where you saved it and double click on it

    If you did everything correctly, the file / folder will be deleted.

    If a confirmation window appears, press Y or Enter on your keyboard

    Advice

    • Symbols can be used in this method. For example, if you want to delete the entire contents of a folder, replace the file name with "*". If you want to delete all files in the folder with the extension.txt (text format), instead of the file name, “*.txt” (without quotes) should be written.
    • To delete multiple files at once, repeat the above steps in the same text document.

Popular by topic