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
- Open the Run dialog and type Explorer, then press Enter. To open the Run dialog, press and hold the WinKey+R simultaneously.
- Press ALT on your keyboard with explorer in focus.
- Click Tools>Folder Options.
- In the Folder Options properties box, click the View tab.
- Uncheck "Hide extensions for known file types" if it is checked.
- Click OK.
Steps
- Open Notepad. To open Notepad, click Start>All Programs>Accessories>Notepad.
- Type "cd" into Notepad (without quotes).
- Find the directory/file which you want to delete, then right click it and choose Properties.
- In the properties box, copy the information listed as "Location".
- 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.
- Now, press Enter on your keyboard to switch to a different line.
- Type "del" in Notepad (without quotes) on the new line.
- 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".
- At the top of Notepad, click File>Save As.
- In the Save As window, choose the Save as Type as "All Files".
- As the File Name, type "yourname.bat" (without quotes) with any name you want in place of "yourname".
- Click Save.
- 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.