Would you like to be able to delete all files in a specific directory with a single mouse click? Are you a programmer looking for a quick and easy way to get your program to delete a file at a certain point in execution? Well, this article is just for you. Read on to find out how.
Initial Steps
- Open the "Run" window by pressing the key combination "Windows + R", type the command "explorer" in the "Open" field and press the "Enter" key. A new "File Explorer" window will open.
- Press the "Alt" key on your keyboard while the "File Explorer" window is active.
- Access the "Tools" menu and choose the "Folder Options" item.
- Go to the "View" tab of the "Folder Options" window.
- Uncheck the "Hide extensions for known file types" checkbox (but only if it is checked).
-
Press the "OK" button.
Steps
Step 1. Start the "Notepad" program
Access the "Start" menu, type in the keyword "Notepad" and choose its icon from the list of results that appears. If you are using an older version of Windows, go to the "Start" menu, select the "All Programs" item, click the "Accessories" icon and finally select the "Notepad" option.
Step 2. Type the command "cd" in the first line of the "Notepad" program window (without including the quotes)
Step 3. Locate the file or folder you want to delete, then right click on it and choose the "Properties" option from the context menu that will appear
Step 4. Copy the text string visible in the "Path" field of the "Properties" window
Step 5. Return to the "Notepad" program window, press the space bar once to insert a blank space after the "cd" command, paste the path you just copied and finally enclose it in quotes
For example, if the path in question is C: / users / Luca, in the document it should appear as follows "C: / users / Luca".
If you need to delete the files inside a specific folder that is currently empty, in step number 3 of the article take note of the complete path of the directory in question followed by the special character / and the name of the latter
Step 6. Now press the "Enter" key on your keyboard to create a new line of text
Step 7. Type the "del" command into the "Notepad" program (without quotes) using the newly created line of text
Step 8. Add a blank space and type the name of the folder or file (in this case also include the extension) you want to delete
Remember to enclose it in quotation marks. For example to delete the directory named "test", you will have to type the following text of the "test". If you want to delete a file called "musica.wav" instead, you will have to use this string of "music.wav".
Step 9. Go to the "File" menu of the "Notepad" program and choose the "Save As" option
Step 10. Now access the "Save as" drop-down menu and choose the "All files (*
*)".
Step 11. Name the file using the format "[filename].bat" (without quotes)
Replace the [filename] parameter with the name of your choice.
Step 12. Press the "Save" button
Step 13. Locate the file you just created and double-click it to section
If you have followed all the steps described so far correctly, the specified folder or file will have been successfully deleted.
If a notification message appears prompting you to confirm that you want to delete the item under consideration, simply press the "Y" key on your keyboard followed by the "Enter" key
Advice
- Using this method you can also use metacharacters. For example, if you need to delete all the contents of a folder, you can replace the file name and extension with the "*" symbol. If you want to delete all files with the ".txt" extension in a directory instead of typing the individual names of the elements to be removed, you can use the "*.txt" parameter.
- To delete multiple files at the same time repeat the steps described in the article using the same text document.