bat + 7z compression bulk "folder"

OFF @echo
for / D %% I in (*) do (echo %% I
D: \ "Program Files" \. 7-the Zip \ 7z.exe -p1 A "%% i.zip" "%% I" / / -p is the password, the password is 1, could be deleted. to a folder named
)
PAUSE

 

FOR %variable IN (set) DO command [command-parameters]

% variable parameter specifies a single letter replaceable.
(set) to specify one or a group of files. You can use wildcards.
command specified command for each file.
command-parameters
specify parameters for a particular command or command-line switches.

To use the FOR command in a batch program, specify %% variable, use a variable
rather than using% variable. Variable names are case sensitive, so different from% i% I.

If you enable command extensions, following the FOR command will support other formats:

FOR /D %variable IN (set) DO command [command-parameters]

If set contains wildcards, the specified match the directory name, rather than match the file name.

FOR /R [[drive:]path] %variable IN (set) DO command [command-parameters]

Check to [drive:] path for the root of the tree, each directory in the FOR statement.
If no directory in the specification / R, then the current directory. If set is just a single point (.) Character,
then enumerate the directory tree.

FOR /L %variable IN (start,step,end) DO command [command-parameters]

This represents a sequence of digits set in increments from the start to the end. Therefore, (1,1,5) to produce a sequence of
12 345, (5, 1,1) to generate a sequence of (54321)

FOR /F ["options"] %variable IN (file-set) DO command [command-parameters]
FOR /F ["options"] %variable IN ("string") DO command [command-parameters]
FOR /F ["options"] %variable IN ('command') DO command [command-parameters]

Or, if there is usebackq options:

FOR /F ["options"] %variable IN (file-set) DO command [command-parameters]
FOR /F ["options"] %variable IN ("string") DO command [command-parameters]
FOR /F ["options"] %variable IN ('command') DO command [command-parameters]

fileset for one or more file names. Before proceeding to the next file in the fileset,
each file is opened, read and processed. Processing includes reading the file, which is divided into lines of text,
and then parsing each line into zero or more symbols. Then symbol string variable values have been found to call the For loop.
In default, / F passes the first blank symbol in each line of each file separately. Skip blank lines.
You can override the default parsing by specifying the optional "options" parameter. This is a quoted string includes one
or more keywords to specify different parsing options. These keywords are:

eol = c - means the end of a line comment character (just a)
Skip the n-= - refers to the number of rows to ignore when the file starts.
delims = xxx - refers to a set of delimiters. This alternative spaces and tabs
default delimiter set.
tokens = x, y, mn - means a symbol which is transmitted to each line of each iteration
of the for itself. This leads to assign additional variable names. mn
format as a range. Specifies the mth through the nth tokens. If
the last character asterisk symbol string,
then an additional variable after the last symbol resolution
allocated and receives the remaining text line.
usebackq - Specifies the new syntax has been used in the following types of cases:
and as a single command string in quotes after performing a
quote character and allows file-set as a literal string command
use double quotes from the expanded file name.

Some examples might help:

FOR /F "eol=; tokens=2,3* delims=, " %i in (myfile.txt) do @echo %i %j %k

It analyzes each line in myfile.txt, ignoring lines that begin with a semicolon, the
each row of the second and third symbols for transfer to the body of the function by commas and / or
delimiter space. Note that this statement for reference function member% i to
obtain a second symbol,% j to obtain a third token, and% k
to get all remaining tokens after the third symbol. For files with spaces in the
name, you need to use double quotes to enclose the file name. In order to use this way to make
use double quotes, also need to use usebackq option, otherwise the double quotes will
be interpreted as defining a string to be analyzed.

% i explicitly declared in the for statement,% j and% k by
tokens = option implicit declarations. Tokens = line can
specify up to 26 symbols, it does not attempt to declare a higher than the letter "z" or
"Z" variables. Remember, FOR variables are single-letter, case sensitive, global variables are;
moreover, can not use more than 52.

May also be used FOR / F in the adjacent string analysis logic, method,
use single quotes the file-set between brackets. In this way, the character
string will be treated as a single input line of a file parsing.

Finally, you can use FOR / F command to parse the output of the command. Is the
file-set between parentheses a back quoted string. The string will
be treated as a command line, passed to a child CMD.EXE, and the output is captured into
memory, and as the file analysis. As shown in the following example:

FOR /F "usebackq delims==" %i IN (`set`) DO @echo %i

It will enumerate the environment variable names in the current environment.

Further, FOR variable references replacement has been enhanced. You can now use the following
syntax options:

% ~ I - remove any quotation marks ( "), extended% I
% ~ fI - expands% I to a fully qualified path name
% ~ dI - only expands% I to a drive letter
% ~ pI - only% I extended to a path
% ~ nI - only expands% I to a file name
% ~ xI - only expands% I to a file extension
% ~ sI - expanded path contains short names
% ~ aI - expands% I to file attributes of file
% ~ tI - expands% I to date / time of the file
% ~ zI - expands% I to size of file
% ~ $ pATH: I - searches the directories listed in the pATH environment variable, and% I extend
to the first fully qualified name found. If the environment variable name
is not defined or the file is not found, this key combination will expand to
an empty string

Modifiers can be combined to get compound results:

% ~ dpI - only expands% I to a drive letter and path
% ~ nxI - only expands% I to a file name and extension
% ~ fsI - only expands% I to a full path name with short names
% ~ dp $ pATH: I - searches the directories listed in the pATH environment variable and expands% I
to the first drive letter and path found.
% ~ ftzaI - expands% I to DIR like output line

In the above examples,% I and PATH can be replaced by other valid values. % ~ Syntax
is terminated by a valid FOR variable name. Select similar% I variable name capitalization of
more readable and avoid confusion with case-insensitive key combination.

Guess you like

Origin www.cnblogs.com/ytCui/p/11249334.html