Deleting files and folders on your computer is simple. You just need to click and press Delete. But have you ever tried creating a .bat file that, when clicked, will delete other files or folders? Here, Mytour introduces you to this trick.
How to create a .BAT file to delete files
Step 1: Right-click on the folder containing the file you want to delete, select New, then choose Text Document
Step 2: Double-click on the New Text Document you just created. The Notepad window appears. Enter the following Code:
@Echo Off
Echo The program has deleted the files RE.TXT and R.TXT on the screen.
Echo.
Delete RE.TXT
Delete R.TXT
Echo.
Echo DELETION SUCCESSFUL...! PRESS ANY KEY TO EXIT...!
pause
EXIT
(Note: Multiple files can be deleted simultaneously using the syntax Del File_Name).
Step 3: Access the File/Save As… Menu
Step 4: Choose the location to save the .BAT file (Here, save it on the Desktop)
Enter the file name XoaFile.bat in the File name field.
In the Save as type field, select All Files
Click on Save to save the .BAT file on the Desktop.
Step 5: After successfully saving the XoaFile.bat file on the Desktop, we can test it by creating 2 files named RE.TXT and R.TXT directly on the Desktop and then double-clicking on XoaFile that we just created.
When running the program, the result will be as follows:
Press any key on the keyboard to end the program.
Creating a .BAT file to delete a folder
Follow step 1 and step 2 similarly to create a file named XoaFolder.bat
In the Notepad window, enter the following Code:
@Echo Off
The program will delete the folder 'Re' on the screen.
Echo.
Rd/s Re
Echo.
Deletion successful...! Press any key to exit...!
pause
EXIT
(Note: The command Rd/s Folder_Name : deletes the folder and all files within it.)
Step 3: Save the file named XoaFolder.bat
Step 4: Create a folder named Re on the Desktop, then double-click on the XoaFolder.bat file you just created. The program will provide the result. (Image below)
Press Y to delete the Re folder.
Press any key to exit. With this method, you can easily delete files and folders on your computer with just a click. Isn't that amazing?