Home > Software engineering >  Novice consult a piece of code
Novice consult a piece of code

Time:09-18

Echo today date is % %
: ac
If % time: ~ % % time: 0, 2 ~ 3, 1 %==233 goto dc
If % time: ~ % % time: 0, 2 ~ 3, 1 %==234 goto dc
If % time: ~ % % time: 0, 2 ~ 3, 1 %==235 goto dc
Copy/y temp. Rar D: \ temp. Rar
Del/f/s/q D: \ temp. Rar
Goto ac
A: dc


Novice just learning, this code to judge what is the meaning of time? Thank you very much!

CodePudding user response:

Not familiar with the syntax,
Guess: take two time starts from zero, 3rd began to take one? Such as: 30 - jump to dc 23:59?

CodePudding user response:

Is this your bat DOS command

CodePudding user response:

Computer composition principle -> DOS command to assembly language, C language (not including the C + +), code writing standards and data structure, compiling principle, operating system and computer network, database principle, the regular expression to other languages (including C + +), architecture...

Start, run, CMD:
C: \ XXX> set/?
, according to a set or delete the CMD. Exe environment variables,

The SET [variable=[string]]

Environment variable specifies the variable name,
A series of string string specified to be assigned to a variable,

To show the current environment variables, type with no parameters SET,

If the command extension is enabled, the SET will change as follows:

Can use only one variable to activate the SET command, equal or values do not show all prefix matching
The SET command is to use the name of the values of all variables, such as:

The SET P

Displays all the variables that starts with a P

If can't find the variable name in the current environment, the SET command will put the ERRORLEVEL
Set to 1,

SET command does not allow variable names contain the equal sign,

In the SET command added two new command line switch:

The SET/A expression
The SET/P variable=[promptString]

/A command line switch to specify the number of the right hand side of the string to be evaluated expression, the expression
Assessment is simple and to the priority order of decreasing supports the following operations:

Group
() -! ~ - unary operator
*/% - arithmetic operator
+ - arithmetic operator
<> - logical shift
& - according to a "and"
^ - according to a "different"
| - according to a "or"
=*=/=%=+=-=- assignment
&=^=|=& lt; <=& gt;>=
- expression delimiters

If you use any logical or operator, you need to use expression string
Quotes, expanding the expression of any non numeric string keys as environment variable
The value of the name, the name of these environment variables has been converted to digital before use, if you specify a
The name of an environment variable, but is not defined in the current environment, then the value will be classified as
Zero, which allows you to use the environment variable values do calculation without having to type in the % symbol
To get their values, if the SET/A in the command line outside the command scripts executed,
It showed that the expression of the final value, the allocation of operators in the allocation of operator
The left require an environment variable name, in addition to the hex 0 x prefix, octal
Have 0 prefix, numeric values for the decimal Numbers, therefore, 0 x12 and 18 and 022
The same, please note octal formula could easily confused: 08 and 09 is invalid number,
Because of 8 and 9 is not a valid octal digits,

/P command line switch allows the numerical set user input variables of a line of input, read input
Line before, according to the specified promptString promptString can is empty,

Environment variable substitution is enhanced as follows:

% % PATH: str1=str2

Will expand the PATH environment variable, using "str2" instead of extending the results of each "str1,"
To effectively removed from the result of extending all the "str1", "str2 can is empty,"
"Str1" with an asterisk can; In this case, the "str1" from extended results of
Appear for the first time to the str1 rest place, has been to keep suitable,

Can also specify the substring for extension,

% % PATH: ~ 10, 5

Will expand the PATH environment variable, and then use only in extension results from 11 (partial
Shift 10) character of the first five characters, if you do not specify a length, then the default
Value, that is, the remainder of a variable numerical, if two Numbers (offset and length) are negative,
Using digital is numerical length plus the specified environment variable offset or length,

PATH: % ~ 10%

Last ten characters, can extract the PATH variable

PATH: % ~ 0, 2%

All the characters will extract the PATH variable, except for the last two,

Finally add the environment variable delay extended support, the support is always according to the default value is
Outage, but also can through the CMD. EXE/V command line switch and be enabled/disabled,
Please refer to the CMD/?

Considering the encountered while reading a line of text now expand the limit, delay environment
Variable expansion is very useful, rather than the execution, the following examples illustrate directly
Variable expansion problem:

The set VAR=before
If "% % VAR"=="before" (
The set VAR=after
If "% % VAR"=="after" @ echo if you see this, it worked
)

Does not show the message, because when reading the first IF statement, BOTH the IF statement
The % of VAR % will be replaced. Reason: it contains an IF style, IF is a
Compound statements, so, in the compound statement IF actually is "before" and
"After", both of which will never be equal, also, the following this example also won't achieve
The desired effect:

The set LIST=
For % I in (*) do the set LIST LIST=% % % I
Echo % % LIST

The reason is that it will not set up a file in the current directory list, but will
The LIST variable set to find the last file, it is also because % % LIST in
FOR statement has been read, only be expanded at a time; And then a LIST variable
Is empty, so we actually perform the FOR loop is:

For % I in (*) do the set LIST=% I

The cycle continues to set the LIST to find the last file,

Delay environment variable extension allows you to use a different character (exclamation mark) in carrying out
Time to extend the environment variables, if the delay variable expansion is enabled to above
Example as shown in the following, in order to achieve the desired effect:

The set VAR=before
If "% % VAR"=="before" (
The set VAR=after
if "! VAR!"=="after" @ echo If you see this, it worked
)

The set LIST=
For % I in (*) do the set LIST=! The LIST! % I
Echo % % LIST

If the command extension is enabled, there are several dynamic environment variables can be extended, but the
Will not appear in the SET according to the list of variables, each variable value is extended,
These variables numerical dynamic calculation will be, if the user to use any of these names
A defined variable, the definition will replace the dynamic definition described below:

% % CD - extension to the current directory string,

% % the DATE - in the same format with the DATE command extension to the current DATE,

% % TIME - in the same format with TIME command extension to the current TIME,

% % RANDOM - extended to arbitrary decimal number between 0 and 32767,

ERRORLEVEL % % - extension to the current ERRORLEVEL numerical,

CMDEXTVERSION % % - extension to the current command processor extensions version number,

% % CMDCMDLINE - extended to invoke the command processor of the original command line,

C: \ XXX>

CodePudding user response:

The
refer to the original poster starfruitssssss response:
echo today date is % %
: ac
If % time: ~ % % time: 0, 2 ~ 3, 1 %==233 goto dc
If % time: ~ % % time: 0, 2 ~ 3, 1 %==234 goto dc
If % time: ~ % % time: 0, 2 ~ 3, 1 %==235 goto dc
Copy/y temp. Rar D: \ temp. Rar
Del/f/s/q D: \ temp. Rar
Goto ac
A: dc


Novice just learning, this code to judge what is the meaning of time? Thank you very much!

The original poster hello, this is a DOS code, including % time % is to display the current time, input time echo % % in the CMD, can appear 15:18:27. 14 this style of string, then: ~ 0, 2 is the interception of meaning, is the # 1/f, friends say, starting from zero bits, intercepted two, then % time: % equals 15 ~ 0, 2, on the basis of the original poster is given conditions from 23:30:00. 00 ~ 23:59:59. 99 are all meet the conditions, why to do so, the demand of the need to look at writing the script,nullnull
  • Related