This batch file can be very useful if needed to delete large folders. Using command line can be over 20 times faster than going through Windows Explorer itself. Finally clearing out the download folder without having to manually take care of it each week or month is a facilitation.
In this tutorial, you will learn about batch file commands and how they are used in batch file scripting or programming.As discussed in the previous tutorial, a batch file is an unformatted text file or script file which contains multiple batch file commands or instructions to achieve a certain task. It has extension of.bat or.cmd.before learning batch file commands. Batch file commands: Windows/DOSFor the ease of learning, we have listed all the batch file commands with relevant examples and explanations below.
Please click on the commands to know the details. ATTRIBThe batch command ATTRIB is used to display the or set an attribute to a file in the working directory.ExampleNow let us suppose we have a file note.txt in our working directory. We will display its file attributes and then make it hidden and read only by adding 'ah' and 'r' attributes to it. And finally, we will remove some attributes we added as well. @echo OFF:: To display attribute of note.txtATTRIB note.txt:: To make it read only by adding 'r'ATTRIB +r note.txtATTRIB note.txt:: To make it hidden by adding 'ah'ATTRIB +ah note.txtATTRIB note.txt:: To remove attribute read onlyATTRIB -r note.txtATTRIB note.txtOutput A note.txtA R note.txtA R AH note.txtA AH note.txtHere in this output, A means Archived, R means Read only and AH means Hidden file.
ECHOThe batch command ECHO is used for echoing commands on/off and printing message to the console.Example @echo OFFecho HelloOutput HelloThis command ECHO displays Hello in the console as shown above.Besides printing message, echo is also used for deciding whether or not to display the command itself. Like in this example as well, in the first line we have turned OFF echo, which makes sure that commands themselves are not printed.If that echo wasn’t turned off, then the output would have been like: C: echo HelloHello. PINGThe batch command PING is used for sending ICMP/IP packets to the designated address over the network.Example @echo OFFPING 127.0.1.1OutputThis script will send packets to address 127.0.1.1 and output will be displayed as follows: Pinging 127.0.1.1 with 32 bytes of data:Reply from 127.0.1.1: bytes = 32 time.
Deleting files is one of the frequently done operation from Windows command prompt. This post explains how to use ‘del’ command from CMD for different use cases like deleting a single file, deleting files in bulk using wild cards etc. Before we start to look at the syntax, note that the command works only for files and can’t handle folders.
How to delete a fileRun del command with the name of the file to be deleted, you are done! Del filenameYou do not see message after running the command if the file is deleted successfully. Error message is shown only when something goes wrong. Delete files in bulkDel command recognizes wildcard(.) and so can be used to delete files in bulk from CMD. Some examples below.To delete all the files in current folder del.To delete all the files with ‘log’ extension del.logDelete all files having the prefix ‘abc’ del abc.Delete all files having ‘PIC’ somewhere in the file name. Del.PIC.The above are the basic use cases of del command.
Continue to read below for non trivial use cases. Delete multiple files‘Del’ command can accept multiple files as argument del filename1 filename2 filename3 filename4.Example: D:dir /s /b1.pdf 2.pdf 3.pdfD:del 1.pdf 2.pdf 3.pdfD:D:dir /s /bD: Delete Read only filesWe can’t delete a read-only file using simple‘del’ command. We get access denied error in this scenario. C:attrib readonlyfile.txtA R C:readonlyfile.txtc:del readonlyfile.txtc:readonlyfile.txt Access is denied.c:A read-only file can be deleted by adding /F flag. Del /F readonlyfile.txtAlternatively, we can use the below command too del /A:R readonlyfile.txt.
Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
February 2023
Categories |