Delete a File in Microsoft Windows Using Batch Files

Want to delete files in a directory with one click? Are you an application developer who wants a free way to delete a file as part of their program? This article is for you. Simply follow these easy steps.

Before beginning

  1. Open the Run dialog and type Explorer, then press Enter. To open the Run dialog, press and hold the WinKey+R simultaneously.
  2. Press ALT on your keyboard with explorer in focus.
  3. Click Tools>Folder Options.
  4. In the Folder Options properties box, click the View tab.
  5. Uncheck "Hide extensions for known file types" if it is checked.
  6. Click OK.

Steps

  1. Open Notepad. To open Notepad, click Start>All Programs>Accessories>Notepad.
  2. Type "cd" into Notepad (without quotes).
  3. Find the directory/file which you want to delete, then right click it and choose Properties.
  4. In the properties box, copy the information listed as "Location".
  5. In Notepad, space once after "cd" and paste what you copied, then type a quote at both ends of it. For example, if I copied C:\users\administrator, then I would have "C:\users\administrator" (with quotes).
    • If you want to delete files from a specific location, but the file in that location doesn't exist, start from step 5, typing the path to the location.
  6. Now, press Enter on your keyboard to switch to a different line.
  7. Type "del" in Notepad (without quotes) on the new line.
  8. Space once, and type the name of the folder or file along with its extension (if any) that you want to delete in quotes.. For example, deleting a folder called Delete Me means that I have to type del "Delete Me". If I want to delete a file called music.wav, I type del "music.wav".
  9. At the top of Notepad, click File>Save As.
  10. In the Save As window, choose the Save as Type as "All Files".
  11. As the File Name, type "yourname.bat" (without quotes) with any name you want in place of "yourname".
  12. Click Save.
  13. Locate the new file where you saved it at, and double click it. If the steps were followed correctly, the file/folder should delete.
    • If you receive a confirmation and you want to delete the file/folder, type Y and press Enter.

Tips

  • You can utilize wildcards with this method. If you want to delete everything in a folder, for example, you can type the file to be deleted as *. If you want to delete everything in a location with a .txt extension (text format), then type *.txt as the file to be deleted.
  • To delete multiple files at once, repeat the steps in the same Notepad document.