Batch Processing instance: File Operations

Source: Internet
Author: User
Tags echo command

01 _ Modify file names in batches. bat

 
: ________________________________________________________ Modifying file names in batches @ echo offecho start to change file name set extension =. RAR: ____________________________________________________/A is used to identify the variable set/a sum = 0for % m in (*) Do (if not "% m" = "batchrename. bat "(: ________________________________________________________ Ren command to modify the file name Ren % m % extension % set/a sum = sum + 1) ECHO file renamed, A total of % sum % files were renamed! Set sum = set extension =

This command is obviously problematic. I will try to modify it later. Here I will write a note: the name will be repeated if no judgment is made during renaming.

02 _ create 100 files from 0 to 99

 
@ Echo offecho: The file is being created: Echo. empty output line, which is equivalent to entering a carriage return echo. echo. :/L indicates that the for loop can only be in the specified range for/L % N in (, 99) Do (::>> redirect symbol echo test document >> test1_1_n.txt) ECHO file created

03 _ automatic cycleProgram

@ Echo offecho: testing whether the host can be pinged to 18.18.18.34 ....: Again: ______________________________________________> NUL indicates that the ping command output is sent to an empty device and not displayed on the screen. Ping 18.18.18.34> NUL :: ______________________________________________ equ determine whether two values are equal if not % errorlevel % equ 0 goto againstart "can communicate with the host normally" Echo can now successfully ping the host 18.18.18.34

04 _ display complete batch path information

 
@ Echo offecho the complete path of the % 0 file currently running is: ____________________________________ % 0 indicates the batch file itself, and % ~ Dp0 indicates the path information on the file echo % ~ Dp0echo. Echo.

05 _ automatically rename the file name to the current system date

@ Echo off: ___________________________________________ % 1 is the file to be renamed by the command line. If not exist % 1 (echo command usage is as follows ::: _______________________________________ % 0 indicates the batch processing NAME echo % 0 filenameecho filename: indicates the file name to be modified. Echo. Echo. Goto end): _______________________________________ % ~ X1 indicates the extension of the % 1 file ,~ X indicates the variable extension set extension = % ~ X1 @ echo on: _______________________________________ tokens is used to define the number of for loop variables, delims is used to define the separator for/F "tokens = 1-3 delims =/-" % A in ('date/t ') do set date = % A % B % C: _______________________________________ here it is particularly stated that the date value should have been changed, but it has not changed here, therefore, the error "Ren % 1% date % extension % echo" is reported. ECHO file % 1 has been renamed to % date % extension % set extension = set date =: End

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.