TXT document and Bat batch file magical

Source: Internet
Author: User

Have you ever imagined yourself becoming an IT elite, a sea of code, a day reading the world that no one else could understand, and what would it be like to ponder the truth through the code? Perhaps you will say, I have not learned the code, also can not be a programmer, how to feel? In fact, if just want to understand the writing program code to achieve some automated processing of happiness does not require advanced theoretical knowledge and protracted learning, TXT this weekday most common temporary document files can help you, with it easy to convert to bat batch file features enough to let you play the imagination, Create your own code to achieve your own proprietary small program.

In fact, the batch file history is quite long, it has existed and played an important role in the DOS era. Batch processing is a simplified scripting language (that is, batch), also known as a batch script, which is the batch processing of an object. The batch file name extension in this article is. bat, except that the batch file extension will also have. cmd, we often see them when we install games and software. The code in the bat batch file is basically based on a DOS system, If you learn DOS or know some DOS commands when you are young, I believe it will be very quick to get started.

Because batch files are a simplified scripting language, it is possible for us laymen to implement simple code programming and functionality in a relatively short time. Before you start, you can think about what simple features you want to implement, such as cleaning up system garbage, copying files in batches, and so on. Here are two simple examples:

To automatically clean up system junk files:

Build a domineering "want Your Life 3000" document

So do it, because in the current Windows environment, there are no. bat batch files in the common types of files, so we can take advantage of the easy transformation of TXT document files. First, we create a new TXT document that gives it a name that you feel cool and fascinating, which is important for you to feel the pleasure of using it. Then double-click to open for code writing. Previously said because the. bat code is based on DOS, so the code uses DOS commands and formats, if there is a basis for direct attempts to write, if there is no basis for reference to the common use of DOS commands and commands used in the format, to write.

Some of the most commonly used DOS commands

Because we are to bulk processing IE cache garbage files, so we need to use the main only a del delete command. Simple DOS commands are typically performed in a xxx[space]x: Directory subdirectory [space] file name. extension, in actual use we often need to follow some variable parameters after the command, and the DEL Related has/P (before deleting each file prompts confirmation). /f (Force deletion of read-only files). /s (delete specified file from all subdirectories)/q (quiet mode). No acknowledgement is required when global wildcard characters are deleted. /A (select the file to delete based on the attribute). We can use these variables based on actual usage requirements. In addition, the cached files of IE are stored in the local settingtemporary Internet Files folder of the system disk, and some system tmp temporary files and some redundant files are also the objects we want to delete, so we can "take Your Life 3000" Write the following code line by row

del/f/s/q "%userprofile%local settingstemporary Internet files*.*"

del/f/s/q%systemdrive%*.tmp

del/f/s/q%SYSTEMDRIVE%*._MP

del/f/s/q%systemdrive%*.log

del/f/s/q%systemdrive%*.gid

del/f/s/q%systemdrive%*.chk

del/f/s/q%systemdrive%*.old

del/f/s/q%windir%*.bak

(You can copy the contents of the red Word directly, note the Half-width colon and the spaces between the text), where *.* represents all the files under the Temporary Internet Files folder (* is a substitution, *.* represents all file names, and all files types).

Write code to TXT document

Change txt "Want your Life 3000" document as Bat batch file

After writing the code to the document, we save and close the document, the document is then renamed and the extension from. txt is changed to. bat, and the system prompts you to determine whether to change the file type, which may affect the executable of the file, and of course choose "Yes" because we want to change the executable of the file, as shown in the figure.

Change to. bat batch File "kill you 3000"

"You're going to kill 3000." Execute Delete file

After changing the extension, you will find that the TXT document automatically becomes a batch file with the gear icon, then it becomes an executable file, double click to open it, it will automatically run the code just written, to delete the system redundant files function. In fact, this is a few years ago on the Internet to strongly delete the system of garbage files, but the code we write today is not as exhaustive. If you have completed the steps above, congratulations, you have written a simple program to remove the system garbage.

Auto Shutdown Assistant:

For example, because after the Windows7, the system shutdown requires the user to click the Start menu button to shut down the system, which is very inconvenient for many users, why not use a simple bat file to implement their own automatic shutdown?

It's easier to actually implement this feature. We still have to build a TXT document as before, and then write the following code to:

Shutdown-s-T 10

Write 10-second automatic shutdown command line

Yes, the code is only one line, well understood, shutdown is shutdown, variable aspect,-L is logoff (cannot be used with option-m),-S is to turn off this computer,-R shuts down and restarts this computer,-a discards system shutdown,-T is the shutdown time is set to xx seconds.

10-Second automatic shutdown batch file

So we passed the combination, easy to get 10 seconds of automatic shutdown code. Write the code to the TXT document you just created and change it to. bat, as shown in the figure.

Shutdown Cancellation plan prompt

Double-click to open, you will find that the system prompts you "will be logged out in 1 minutes", time you can pass the variable free control, so you do not have to shut down the time to go to the menu to click the Shutdown button.

In fact, the author simply gives two simple examples of my ability. If you are just a layman, then I would like to spend 20 minutes to understand these simple DOS command combination, you can also get such as automatic bulk export mobile disk photos, music files, automatically query the target disk fixed type of file, Automatically batch open applications and many other functions. If you are familiar with DOS commands, then these things for you must be a piece of cake, must be able to combine a more useful function, the combination of these code for us to use, to create a only belong to their own automated system, is certainly quite a sense of a thing, as you also come to feel.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.