PDF download Download Article PDF download Download Article

This wikiHow teaches you how to delete a file on your Windows computer by using a Batch file. Batch files are small files which can run commands via your computer's built-in Command Prompt program. Once you understand how to create a basic Batch file that can delete other files, you can create a more advanced Batch file to delete all files matching a specific file type from a specific folder, or even delete every file from a folder and its subfolders.

Part 1
Part 1 of 5:

Finding the File's Information

PDF download Download Article
  1. Go to the location of the file that you want to remove via Batch file.
  2. Doing so prompts a drop-down menu.
    Advertisement
  3. It's at the bottom of the drop-down menu. This will open a pop-up window.
  4. In the "Type of file" section, look for the three- or four-letter extension in parentheses. This is the extension you'll need to add onto your file's name later.
    • For example, if you have a text file, you'll see "Text Document (.txt)" to the right of the "Type of file" heading.
    • If you see "File folder" listed as the file type, you'll have to close the Properties window, click once the file you want to check, and then right-click it again and click Properties.
  5. Click and drag your mouse across the address listed in the "Location" section of the Properties window, then press Ctrl + C . This will add the address to your computer's clipboard. At this point, you're ready to begin writing the Batch file.
  6. Advertisement
Part 2
Part 2 of 5:

Writing the Batch File

PDF download Download Article
  1. Click the Windows logo in the bottom-left corner of the screen.
  2. Type in notepad , then click Notepad at the top of the Start window. The Notepad window will open.
  3. Type in cd and press the spacebar, then paste in your copied address by pressing Ctrl + V and press Enter . This tells the command to look in the folder in which your file is stored.
    • For example, if your file is on the desktop, your command might read cd C:\Users\YourName\Desktop .
    • If you don't do this step, the "Delete" command will look for your file in a system folder instead.
  4. On the line directly below the "Change Directory" command, type in del and press the spacebar.
  5. Type a quotation mark, type in the file's name exactly as it appears (including spaces, special characters, and capitalization), type in a period and the file's extension, and type the closing quotation mark.
    • For a text file named "Bananas", for example, you would type in "Bananas.txt" as the file name and extension.
    • At this point, the entire second line should read del "file name.extension" where "file name" is replaced by the file's name and ".extension" is replaced by the file's extension.
  6. If you want to delete multiple files from a folder, press Enter to start a new line, then type in del and a space followed by the other file's name and extension; repeat this process as needed until all of the files you want to remove are named in the file on their own lines.
  7. Advertisement
Part 3
Part 3 of 5:

Saving and Executing the Batch File

PDF download Download Article
  1. It's in the top-left corner of the Notepad window. A drop-down menu will appear.
  2. This option is in the drop-down menu. Doing so opens the Save As window.
  3. Type whatever you want to name your Batch file into the "File name" text box, then type in .bat at the end of the file's name.
    • For example, to name your Batch file "fruit", you would type in fruit.bat here.
  4. You'll find this option near the bottom of the window. Clicking it prompts a drop-down menu.
  5. It's in the drop-down menu.
  6. Click a folder on the left side of the window (e.g., Desktop ) to select that folder as the place in which to save your Batch file.
  7. It's in the bottom-right corner of the window. This will save your Batch file in the selected location.
  8. When you run your Batch file, the "del" command will tell your computer to remove permanently the named files (as opposed to moving them to the Recycle Bin). Because of this, you should be careful when executing your Batch file.
  9. When you're ready to delete your named file(s), simply double-click the Batch file to run it. You should see the file(s) disappear after a moment.
  10. Advertisement
Part 4
Part 4 of 5:

Clearing a Folder of One File Type

PDF download Download Article
  1. If you want to clear all files of a specific file type (e.g., text files) from a folder, you can use a Batch file. This is useful if you have a folder which automatically fills up with various files.
  2. Double-click the folder that you want to clear to open it.
  3. Do the following:
    • Right-click the type of file you want to delete.
    • Click Properties .
    • Look at the extension in the "Type of file" section.
  4. Click the address bar at the top of the folder to highlight the address, then press Ctrl + C to copy it.
    • If clicking the address bar doesn't highlight the address, click and drag across the address to highlight it.
  5. Click Start
    Windows Start
    , type in notepad , and click Notepad when it appears at the top of the Start menu.
  6. Type in cd and press the spacebar, then press Ctrl + V to paste in the folder's address.
  7. Press Enter to start a new line below the first one, then type in del and press the spacebar.
  8. Instead of typing in a specific file's name, you'll type in a quotation mark, an asterisk, the extension, and another quotation mark. This tells your computer to delete any files ending in your specified extension.
    • For example, if you want to empty the folder of text files, your "Delete" line would say del "*.txt" .
  9. If you want to empty the folder of more than one file type, start a new line by pressing Enter , then type in the "Delete" command followed by the extension for the file type.
  10. Do the following:
    • Click File .
    • Click Save As... .
    • Type whatever you want to name your Batch file followed by .bat into the "File name" text box.
    • Click the "Save as type" box, then click All Files .
    • Select a save location on the left side of the window, then click Save .
  11. Simply double-click the Batch file to do so. This will remove any file(s) matching your specified extension(s) from the folder.
    • If you ever move the folder, you'll need to edit the Batch file to include the updated folder's address.
  12. Advertisement
Part 5
Part 5 of 5:

Emptying a Folder of All Files

PDF download Download Article
  1. If you want to remove an entire folder's file contents without deleting the subfolders inside of the main folder, you can use a Batch file to do so.
    • This method won't delete folders inside of the directory, but it will remove all files from those folders.
  2. This will open a drop-down menu.
  3. It's at the bottom of the drop-down menu. Doing so opens the Properties window.
  4. Click and drag your mouse across the address in the "Location" section, then press Ctrl + C .
  5. Click Start
    Windows Start
    , type in notepad , and click Notepad when it appears at the top of the Start menu.
  6. Type in cd and press the spacebar, then press Ctrl + V to paste in the folder's address.
  7. Press Enter to start a line below the "Change Directory" command, then do the following:
    • Type in del and then press the spacebar.
    • Type in /S /Q and then press the spacebar. The "/S" ensures that any folders inside of the main folder also have their files deleted, and the "/Q" removes the confirmation prompt.
    • Paste in the folder's address from earlier.
    • Type in a backslash (\).
    • Type in the folder's name exactly as it appears in the address bar when you open the folder.
  8. Do the following:
    • Click File .
    • Click Save As... .
    • Type whatever you want to name your Batch file followed by .bat into the "File name" text box.
    • Click the "Save as type" box, then click All Files .
    • Select a save location on the left side of the window, then click Save .
  9. Whenever you want to clear out the folder and its subfolders, double-click the Batch file.
  10. Advertisement

Community Q&A

Search
Add New Question
  • Question
    How do I delete the operating system?
    Cameron Paxton
    Community Answer
    You can't actually do that, not unless you are from the corporation that made the device, or you can inspect element and force a code to run a simple deletion function, and that would seriously take some delicate thinking.
  • Question
    Can you explain what save as rtf file to docx means?
    NSA
    Community Answer
    Open the file in any text editor such as notepad, wordpad, notepad++, etc. Then press CTRL+S or manually go to file and click "save as". From here you will need to change the file type bar to "All Files" and when saving the file you will need to save it as FileName.docx.
  • Question
    How can I restore a deleted file?
    Community Answer
    Check the recycling bin and see if it's still there. If not, unless you have a backup of your file or have it saved on another device, you can't restore it.
See more answers
Ask a Question
      Advertisement

      Video

      Tips

      • If you want to edit a Batch file, right-click the file, then click Edit in the resulting drop-down menu. This will open the file in Notepad; you can edit it there and then press Ctrl + S to save your changes.
      • When running a Batch file, you may see a Command Prompt window open very briefly.
      Submit a Tip
      All tip submissions are carefully reviewed before being published
      Name
      Please provide your name and last initial
      Thanks for submitting a tip for review!
      Advertisement

      Warnings

      • Batch files used in this manner will permanently delete the named files instead of just moving them to the Recycle Bin.


      Advertisement

      About This Article

      Article Summary X

      1. Create a blank text file in Notepad.
      2. Type "cd" followed by the full path to the directory containing the file.
      3. On the next line, type "del" followed by the name of the file to delete in quotes.
      4. Save the file with the ".bat" extension.
      5. Run the file.

      Did this summary help you?
      Thanks to all authors for creating a page that has been read 213,567 times.

      Is this article up to date?

      Advertisement