Window batch processing-6 rem, window-6rem

Source: Internet
Author: User

Window batch processing-6 rem, window-6rem

Purpose:

A comment command to add corresponding instructions to the batch.

Format:

Rem [comment]


Demo:

Bat

@ Echo offpause rem this is an explanation of pause echo xxxpause

Result:






Back up ftp files in batches and use bat in the window

Maybe I can only use this batch for FTP servers running IIS. I have never used an FTP server created using other software. I am not clear about the format of the result returned by the dir command. Hi if you have any questions.
The general workflow is like this. First, the remote folder list is empty. Write a line "/" (remote root folder ). Then start the loop. In the nth loop, obtain the list of subfolders and files in the nth row folder of the path folder list, process the obtained list, and add the subfolders in the list to the remote folder list, download the files in the list. Loop until the nth action in the last remote folder list is null.

If you do not need to save the folder structure, you can use the lanny119 method and use the mget command to download all the files.

The environment changes made in the rem setlocal batch processing only affect the current batch processing. The preceding @ parameter does not display the command itself.
@ Setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
Rem display command itself off
@ Echo off
Rem fill in the ftp server address or domain name
Set ftpsvr =
Rem User Name
Set user =
Rem Password
Set pass =
Rem fill in the folder to save the backup
Set archdir = D: \ backup
Rem fill in the WinRAR installation folder, such as: C: \ Program Files \ WinRAR
Set rardir =
Rem sets the path of the temporary folder to be used as the environment variable mytemp
Set mytemp = % temp % \ ftp. x
Rem prevents operations from being affected by folders or files of the same name. Delete all files.> Nul does not display Echo 2> nul does not display error messages
Rd/s/q "% mytemp %"> nul 2> nul
Del/a/f "% mytemp %"> nul 2> nul
Md "% mytemp %"

Rem writes a slash to % mytemp % \ rdl. A slash indicates the remote root folder. Rdl is used to save the remote folder list.
Echo/> "% mytemp % \ rdl"
Rem remote folder count of downloaded files
Set dcount = 0
Rem cycle
: Cycle
Rem obtains the list of files and subfolders in the remote folder.
Rem writes skip = n because the for below is to be executed multiple times and not the first to skip the processed rows.
However, an error occurred while writing skip = 0 during the first execution. Therefore, ship = is not written for the first execution.
If % dcount % = 0 set oo =
If not % dcount % = 0 set oo = ^ skip = % dcount %
Rem skips the specified number of rows and assigns % I each time a row from the rdl file.
For/f "tokens = * % oo %" % I in (% mytemp % \ rdl) do (
Rem prepares command files for ftp (used to obtain the file list ). In the first line, replace the content of the ftpcmd file with> append.
Echo open % ftpsvr %> "% mytemp % \ ftpcmd"
Echo % user %> "% mytemp % \ ftpcmd"
Echo % pass %> "% mytemp % \ ftpcmd"
The content written by rem is to change the remote working directory to the directory obtained by the for statement.
Echo c... the remaining full text>

How to read file content variables in window batch processing?

@ Echo off
Setlocal enabledelayedexpansion
For/f "tokens = 1-3 delims =," % I in (test.txt) do (
Set BL1 = % I
Set BL2 = % j
Set BL3 = % k
Echo variable 1 =! BL1! Variable 2 =! BL2! Variable 3 =! BL3 !)

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.