The commands you gave are basically full of errors. Please carefully check whether you have given the complete command line. Judging from the command line, this for command should be the for command used under 2000/xp/2003. For detailed usage, please refer to for /? under the corresponding system. 1. The correct command line of the first command should be like this:
for /R D:\MY %%a in (*.txt) do md "%%~fna"
Here, /R D:\MY means a directory that the for command should process, and %%~fna is the enhanced usage of variable substitution in for. But when actually running this command, it is meaningless and errors will definitely occur. I don't know what function this command is supposed to achieve. 2. The correct command line of the second command:
for /F "delims=/" %%i in ('dir /b/s *.*'

do dir /b/s *.txt *.rar | find "%%i" || del "%%i"
The function of this command is to delete all files with extensions other than txt and rar under the current directory. Help for the for command under Windows 2003:
Execute a specific command for each file in a group. FOR %variable IN (set) DO command %variable specifies a single-letter replaceable parameter.
(set) Specifies one or a group of files. Wildcards can be used.
command Specifies the command to be executed for each file.
command-parameters
Specifies parameters or command line switches for a specific command. When using the FOR command in a batch program, use %%variable instead of %variable to specify the variable. Variable names are case-sensitive, so %i is different from %I. If command extensions are enabled, the following additional FOR command formats will be supported:FOR /D %variable IN (set) DO command If wildcards are included in the set, it specifies a match with the directory name instead of the file name. FOR /R path] %variable IN (set) DO command Checks the directory tree rooted at path and points to the FOR statement in each directory. If no directory is specified after /R, the current directory is used. If the set is only a single dot (.) character, the directory tree is enumerated. FOR /L %variable IN (start,step,end) DO command The set represents a sequence of numbers from start to end in increments. Therefore, (1,1,5) will generate the sequence 1 2 3 4 5, and (5,-1,1) will generate the sequence (5 4 3 2 1). FOR /F %variable IN (file-set) DO command
FOR /F %variable IN ("string"

DO command
FOR /F %variable IN ('command'

DO command Or, if the usebackq option is used:FOR /F %variable IN (file-set) DO command
FOR /F %variable IN ("string"

DO command
FOR /F %variable IN ('command'

DO command filenameset is one or more file names. Before continuing to the next file in filenameset, each file has been opened, read, and processed.
Processing includes reading the file, dividing it into lines of text, and then parsing each line into zero or more symbols. Then the for loop is called with the found symbol string variable value. By default, /F separates through the first blank symbol in each line of each file. Blank lines are skipped. You can substitute the default parsing operation by specifying the optional "options" parameter. This quoted string includes one or more keywords specifying different parsing options. These keywords are: eol=c - Refers to the end of a line comment character (just one)
skip=n - Refers to the number of lines to be ignored at the beginning of the file.
delims=xxx - Refers to the delimiter set. This replaces the default delimiter set of spaces and tabs.
tokens=x,y,m-n - Refers to which symbols of each line are passed to the for itself in each iteration. This leads to the allocation of additional variable names. The m-n format is a range. The m-th symbol is specified by the nth symbol. If the last character in the symbol string is an asterisk, then additional variables will be allocated and accept the reserved text of the line after the last symbol is parsed.
usebackq - Specifies that the new syntax has been used in the following situations:
When executing a backquoted string as a command and a single
quote character is a literal string command and allows file names to be enclosed in double quotes in filenameset. Some examples may be helpful:FOR /F "eol=; tokens=2,3* delims=, " %i in (myfile.txt) do @echo %i %j %k Will analyze each line in myfile.txt, ignore those lines starting with a semicolon, and pass the second and third symbols in each line to the for program body; delimited by commas and/or spaces. Please note that the statement of this for program body refers to %i to get the second symbol, refers to %j to get the third symbol, and refers to %k
To get all remaining symbols after the third symbol. For file names with spaces, you need to enclose the file name in double quotes. To use double quotes in this way, you also need to use the usebackq option, otherwise, the double quotes will
be understood as being used to define a string to be analyzed. %i is specifically explained in the for statement, and %j and %k are specifically explained through the tokens= option. You can specify up to 26 symbols in a line through tokens=, as long as you do not try to explain a variable higher than the letter 'z' or 'Z'. Please remember that FOR variables are single letters, case-sensitive, and global; and,
Moreover, there cannot be more than 52 in use at the same time. You can also use the FOR /F analysis logic on adjacent strings; the method is to enclose the filenameset between parentheses with single quotes. In this way, the character
string will be regarded as a single input line in a file. Finally, you can use the FOR /F command to analyze the output of a command. The method is to turn the filenameset between parentheses into a backquoted string. This string will
be regarded as a command line, passed to a sub CMD.EXE, and its output will be captured
into memory and regarded as a file for analysis. Therefore, the following example: FOR /F "usebackq delims==" %i IN (`set`) DO @echo %i Will enumerate the names of environment variables in the current environment. In addition, the replacement of FOR variable references has been enhanced. You can now use the following
option syntax: ~I - Remove any quotes ("

, expand %I
%~fI - Expand %I to a fully qualified path name
%~dI - Only expand %I to a drive letter
%~pI - Only expand %I to a path
%~nI - Only expand %I to a file name
%~xI - Only expand %I to a file extension
%~sI - The expanded path only contains short names
%~aI - Expand %I to the file attributes of the file
%~tI - Expand %I to the date/time of the file
%~zI - Expand %I to the size of the file
%~$PATH:I - Find the directory listed in the path environment variable and expand %I
to the first found fully qualified name. If the environment variable name
is not defined, or the file is not found, this combination key will expand to
an empty string Multiple results can be obtained by combining modifiers: %~dpI - Only expand %I to a drive letter and path
%~nxI - Only expand %I to a file name and extension
%~fsI - Only expand %I to a complete path name with a short name
%~dp$PATH:I - Search the directory listed in the path environment variable and expand %I
to the first found drive letter and path.
%~ftzaI - Expand %I to a DIR-like output line. In the above examples, %I and PATH can be replaced with other valid values. The %~ syntax
ends with a valid FOR variable name. Choosing a capital variable name like %I
is easier to read and avoids confusion with case-insensitive combination keys.