How Make A Batch File That Cleans Your System
In this tutorial, you will larn most 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.
Click here to get through the introduction of the batch file earlier learning batch file commands.
Batch file commands: Windows/DOS
For the ease of learning, we accept listed all the batch file commands with relevant examples and explanations below. Please click on the commands to know the details.
List of batch file commands
Note: Batch file commands are not case sensitive
ASSOC
The batch command ASSOC associates a file extension with a file type, or list all associations.
Example
@echo OFF ASSOC | find ".txt" suspension Output
.txt = textfile
As shown in above output, it displays the file clan for.txt extension.
If only ASSOC is written and executed, it will display all the file associations for every extension, instead of only .txt extension.
click hither to go back to list of commands
ATTRIB
The batch command ATTRIB is used to display the file attributes or set an attribute to a file in the working directory.
Example
At present let usa suppose nosotros have a file note.txt in our working directory. We volition display its file attributes and so brand it hidden and read simply by adding 'ah' and 'r' attributes to it. And finally, nosotros volition remove some attributes nosotros added likewise.
@echo OFF :: To display attribute of annotation.txt ATTRIB annotation.txt :: To get in read just past adding 'r' ATTRIB +r note.txt ATTRIB note.txt :: To make it hidden by calculation 'ah' ATTRIB +ah notation.txt ATTRIB note.txt :: To remove attribute read only ATTRIB -r note.txt ATTRIB notation.txt Output
A note.txt A R note.txt A R AH note.txt A AH note.txt
Here in this output, A means Archived, R means Read only and AH means Subconscious file.
click here to get back to list of commands
CD
The batch command CD helps in navigating through unlike directories and changing directories or displaying electric current directory.
Example
@repeat OFF :: CD without any parameters displays the current working directory CD :: Changing to the parent directory 1 level up CD.. CD :: Changing the path to Programs CD\Programs CD pause Output
C:\Users\abc C:\Users C:\Programs
click here to get dorsum to list of commands
CHKDSK
The batch command CHKDSK is used for checking error in the disk.
Example
@repeat OFF CHKDSK click here to become dorsum to listing of commands
CHOICE
The batch command CHOICE provides a list of options to the user.
Instance
@echo OFF ECHO You want java? ECHO Enter Y for yes ECHO Enter N for no Selection /c YN /yard "Yes or No" Output
Now that script will produce following output.
Yous desire coffee? Enter Y for yep Enter N for no Yes or No [Y,N]?
Now the console waits for your input and in one case you enter your reply it will terminate.
click here to get back to list of commands
CLS
The batch control CLS clears the screen.
Instance
@repeat OFF CLS pause This command just clears all the logs in command prompt screen.
click here to go back to listing of commands
CMD
The batch command CMD invokes a new control prompt window.
Instance
@repeat OFF CMD click here to go dorsum to list of commands
COMP
The batch command COMP compares the size of two files and checks if they are dissimilar in size.
Example
@echo OFF COMP C:\abc.txt C:\xyz.txt click hither to go dorsum to list of commands
CONVERT
The batch command CONVERTS the volumes or drives from one format to some other i.e from Fatty to NTFS.
Case
@echo OFF Catechumen D:\ click here to go back to list of commands
COPY
The batch command Re-create is used for copying files from ane location to another.
Case
@repeat OFF :: For copying from one drive to some other -xyz.txt from D:\ to Eastward:\ COPY D:\xyz.txt E:\ :: If file has whitepace between name - use double quote Re-create "D:\my file.txt" E:\ click here to become dorsum to list of commands
DATE
The batch control Date displays the current engagement in the arrangement.
Instance
@echo OFF echo %Date% Output
Friday 07/07/2017
This command DATE displays arrangement date in control prompt equally shown above.
click here to go dorsum to list of commands
DEL
The batch command DEL is used for deleting files.
Example
@echo OFF :: To delete a unmarried file xyz.txt DEL D:\xyz.txt :: To delete all the files of .txt extensions and inquire for confirmation before deleting DEL /p/s D:\*.txt :: Remove \p to delete without confirmation DEL /due south D:\*.txt Annotation: DEL command merely deletes files, non directories.
click here to go back to listing of commands
DIR
The batch command DIR lists all the contents of directories.
Instance
@echo OFF :: To list all the contents of current directory DIR :: To listing all the hidden files of working directory DIR /ah :: To list all files with .php extensions DIR *.php DISKPART
The batch command DISKPART shows the properties of a disk partitioning.
Case
@echo OFF DISKPART This script will enquire for users permission to check the backdrop of disk partition and if allowed, will brandish following output in the console depending on disk properties.
click here to go dorsum to list of commands
DRIVERQUERY
The batch command DRIVERQUERY displays all the drivers installed and their properties.
Case
@echo OFF DRIVERQUERY Output
This output shows the fraction of drivers list with their properties and installed date. DRIVERQUERY command shows all the drivers listing, which is huge.
click here to go back to listing of commands
Repeat
The batch command Repeat is used for echoing commands on/off and printing bulletin to the console.
Case
@repeat OFF echo Howdy Output
Hello
This control Echo displays Hi in the console as shown above.
Besides printing message, repeat is also used for deciding whether or not to brandish the control itself. Like in this example also, in the commencement line we have turned OFF echo, which makes sure that commands themselves are not printed.
If that repeat wasn't turned off, then the output would have been similar:
C:\> echo Hi Hullo
click here to go back to list of commands
EXIT
The batch command EXIT terminates and exits the console.
Example
@echo OFF echo HI EXIT In this instance, as presently as How-do-you-do is printed in the console, EXIT control will cease the programme and close the output panel.
click hither to go back to list of commands
Expand
The batch command Expand extracts the contents of .cab file.
Example
@echo OFF Aggrandize xyz.cab This script will extract all the contents of xyz.cab file to the same location where xyz.cab is located.
click here to get back to listing of commands
FC
The batch command FC finds the difference betwixt the two files and displays them to console.
Example
@echo OFF FC D:\a.txt D:\b.txt This script will detect the difference in the content of both files and list out all of them.
click here to get dorsum to list of commands
FIND
The batch command FIND search the given file to discover the desired string and if located, it displays the respective line in which the string exists.
Example
@repeat OFF Detect "find me" example.txt This script volition search for the string "detect me" in instance.txt file and if it exists in example.txt, it volition display the corresponding line on the console.
click hither to go back to list of commands
FORMAT
The batch command FORMAT is used for formatting a bulldoze of format Fatty 16/32 or NTFS in Windows.
Example
@repeat OFF FORMAT E:\ This script will format East drive and overwrite previous contents.
click here to get dorsum to list of commands
HELP
This might be the one of the nigh important batch file commands because with this HELP control we tin can know most all the other commands used in batch file or command prompt.
Case
@repeat OFF HELP At present this will display all the bachelor commands with their functionalities in the console.
Since the list of commands is then much more, nosotros accept sliced the list and shown few here.
At present that nosotros accept a list of batch file commands, we can also view details of their syntax and functionalities in following way:
@echo OFF :: But type help and the command yous want to know about HELP re-create Now this will display details of the copy control.
As yous can run across, information technology HELP Re-create displays all the details well-nigh Re-create command.
click hither to go back to list of commands
IPCONFIG
The batch command IPCONFIG displays Windows IP configuration.
Example
@echo OFF IPCONFIG This script will generate following output.
P.South: We have hidden iPV6 accost in above output.
click here to get dorsum to list of commands
LABEL
The batch command Characterization displays the characterization of a drive or volume and is also is used for calculation, setting or removing a deejay label.
Example
@echo OFF Label Now this will display the characterization of your working directory and you can set, remove or add another label.
For case, my working directory is D: and has label 'apps'. Then, it will generate post-obit output:
click hither to become back to list of commands
MD
The batch command Dr. creates a new directory or binder in the working directory.
Example
@echo OFF MD abc This program will create a new directory abc in electric current working location.
click hither to go dorsum to listing of commands
More
The batch control More displays the content of a file one by one.
Case
@echo OFF MORE D:\example.txt This program volition display the contents of example.txt line by line, 1 at a time.
click here to go back to listing of commands
Movement
This batch command moves files from one directory to some other, rename the directories and motility the directories besides.
Example
@echo OFF :: To movement xyz.txt from dir1 to dir2 Movement C:\dir1\xyz.txt C:\dir2 :: To rename directory dir1 to dir2 Motion C:\Program\dir1 C:\Program\dir2 :: To move directory dir1 from D:\ to D:\music MOVE D:\dir1 D:\music\ In this style, Motion control can be used to move files, directories and rename directories.
click here to go back to list of commands
Internet
The batch command NET is used for many network functionalities depending upon the commands used.
Instance
To display the users:
@echo OFF Net users This volition generate post-obit output:
Like users, there are many other commands:
- net accounts
- net estimator
- cyberspace config
- net go along
- net file
- net group
- net help
- cyberspace name
- net pause
- net print
- net ship
- net session
- cyberspace share
- net start
- net statistics
- internet cease
- net time
- internet utilise
- net view
click here to go back to list of commands
PATH
The batch command PATH displays the path variable or it tin exist used to set path variable.
Instance
@echo OFF ECHO %PATH% This programme volition display the path of the current working directory.
click here to get dorsum to listing of commands
PAUSE
The batch command PAUSE is used for holding the output screen till user enters a variable or a value.
Example
@repeat OFF ECHO hello intermission This program will print hullo in the console and show the message 'Press whatever fundamental to keep..' and wait for the input from the user.
click here to go back to listing of commands
PING
The batch command PING is used for sending ICMP/IP packets to the designated address over the network.
Example
@echo OFF PING 127.0.i.1 Output
This script will send packets to address 127.0.1.1 and output will exist displayed as follows:
Pinging 127.0.1.one with 32 bytes of information: Respond from 127.0.1.1: bytes = 32 fourth dimension<1ms TTL = 128 Reply from 127.0.one.1: bytes = 32 fourth dimension<1ms TTL = 128 Ping statistics for 127.0.1.1: Packets: Sent = two, Received = 2, Lost = 0 (0% loss), Estimate round trip times in milli-seconds: Minimum = 0ms, Maximum = 0ms, Average = 0ms
click hither to go back to list of commands
RD
The batch command RD is used for removing the empty directories, directories with contents or files inside cannot be removed with RD command.
Case
@repeat OFF :: To remove directory xyz from C:\> RD C:\xyz :: To remove multiple directories from working location RD dir1 dir2 click here to go back to list of commands
REM
The batch command REM signifies comments in the batch script.
Example
@echo OFF REM This is a annotate Anything written later REM is interpreted equally a annotate and is non executed in batch programs.
click hither to get back to list of commands
REN
The batch control REN is used for renaming files and directories.
Example
@repeat OFF :: To rename ten.php to y.php REN C:\x.php C:\y.php click hither to become back to list of commands
Prepare
The batch control Ready displays the list of environment variables of the system.
Example
@echo OFF SET click here to go back to list of commands
SHUTDOWN
The batch control SHUTDOWN when invoked, shuts downwards the computer.
Example
@repeat OFF SHUTDOWN click hither to go back to list of commands
SORT
The batch command SORT is used to sort the content of the file alphabetically.
Example
@echo OFF SORT D:\example.txt This script will sort the content of case.txt alphabetically either in ascending or descending social club.
click here to become back to list of commands
START
The batch control First is used to open a file or start a new plan.
Case
@echo OFF Outset paint.exe This program will start the application paint if it is in the working location, else you volition have to explicitly signal the path of that program likewise.
click hither to become back to list of commands
SYSTEMINFO
The batch control SYSTEMINFO displays all the configuration of the reckoner and operating system.
Example
@echo OFF SYSTEMINFO This will generate post-obit output depending upon the calculator:
Of course, the details will be much more than than this, merely please endeavor and look on your PC.
click here to become back to list of commands
TASKKILL
The batch commandTASKKILL is used to terminate a running chore
Instance
If you were to terminate the notepad running in your PC, then post-obit script is used.
@echo OFF TASKKILL /im notepad.exe click here to go back to list of commands
TASKLIST
The batch command TASKLIST lists all the running tasks in the console.
Example
@echo OFF TASKLIST click here to go back to listing of commands
Time
The batch command TIME is used to display or ready the organization time.
Example
@echo OFF Echo %TIME% Output
18:01:22:06
The current time is displayed in the console.
click here to go back to listing of commands
Championship
The batch command Title sets new title for output console.
Case
@echo OFF Title New Panel This script will ready the title of output console to 'New Console'. Thus the output console will look like:
click hither to go back to list of commands
TREE
The batch command TREE displays the tree diagram of the subdirectories to the final level.
Instance
I have a folder movies. And then, if I were to run TREE in that movie binder, information technology will create a tree of movies inside that binder and also the subdirectories where there is movie file and subtitle file.
@echo OFF TREE D:\movies Output
This script will generate following output.
click here to go back to list of commands
Type
The batch command TYPE is used for displaying the content of a file to an output panel.
Example
@repeat OFF Type C:\notes.txt interruption This programme will display all the contents of notes.txt to the panel.
click here to become back to list of commands
VER
The batch command VER displays the version of Windows or MS-DOS.
Example
@echo OFF VER interruption Output
Microsoft Windows [Version 10.0.14393]
click here to go back to list of commands
VOL
The batch command VOL displays the current volume label of Windows.
Example
@echo OFF VOL Output
Microsoft Windows [Version 10.0.14393]
click here to go back to list of commands
XCOPY
The batch command XCOPY is similar to Re-create control but Re-create command copies single file whereas XCOPY command copies unabridged directories including subdirectories.
Example
@echo OFF XCOPY D:\examination.txt to E:\ This script will re-create test.txt from D drive to E drive.
click here to go back to list of commands
So, these are the batch file commands forth with examples.
We promise you lot observe these batch file commands easy to learn. We will talk over more than avant-garde concepts in next tutorials.
Source: http://www.trytoprogram.com/batch-file-commands/
Posted by: moultrieprestriall.blogspot.com

0 Response to "How Make A Batch File That Cleans Your System"
Post a Comment