DOS: Unterschied zwischen den Versionen

Aus Claudio's Wiki
Wechseln zu: Navigation, Suche
(DOS Befehle)
(DOS Befehle)
Zeile 94: Zeile 94:
 
;for
 
;for
 
<code>
 
<code>
   
+
  P:\Cobian_Backup\Claudio>for /?
 +
Runs a specified command for each file in a set of files.
 +
 
 +
FOR %variable IN (set) DO command [command-parameters]
 +
 
 +
  %variable  Specifies a single letter replaceable parameter.
 +
  (set)      Specifies a set of one or more files.  Wildcards may be used.
 +
  command    Specifies the command to carry out for each file.
 +
  command-parameters
 +
            Specifies parameters or switches for the specified command.
 +
 
 +
To use the FOR command in a batch program, specify %%variable instead
 +
of %variable.  Variable names are case sensitive, so %i is different
 +
from %I.
 +
 
 +
If Command Extensions are enabled, the following additional
 +
forms of the FOR command are supported:
 +
 
 +
FOR /D %variable IN (set) DO command [command-parameters]
 +
 
 +
    If set contains wildcards, then specifies to match against directory
 +
    names instead of file names.
 +
 
 +
FOR /R [[drive:]path] %variable IN (set) DO command [command-parameters]
 +
 
 +
    Walks the directory tree rooted at [drive:]path, executing the FOR
 +
    statement in each directory of the tree.  If no directory
 +
    specification is specified after /R then the current directory is
 +
    assumed.  If set is just a single period (.) character then it
 +
    will just enumerate the directory tree.
 +
 
 +
FOR /L %variable IN (start,step,end) DO command [command-parameters]
 +
 
 +
    The set is a sequence of numbers from start to end, by step amount.
 +
    So (1,1,5) would generate the sequence 1 2 3 4 5 and (5,-1,1) would
 +
    generate the sequence (5 4 3 2 1)
 +
 
 +
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 usebackq option present:
 +
 
 +
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]
 +
 
 +
    filenameset is one or more file names.  Each file is opened, read
 +
    and processed before going on to the next file in filenameset.
 +
    Processing consists of reading in the file, breaking it up into
 +
    individual lines of text and then parsing each line into zero or
 +
    more tokens.  The body of the for loop is then called with the
 +
    variable value(s) set to the found token string(s).  By default, /F
 +
    passes the first blank separated token from each line of each file.
 +
    Blank lines are skipped.  You can override the default parsing
 +
    behavior by specifying the optional "options" parameter.  This
 +
    is a quoted string which contains one or more keywords to specify
 +
    different parsing options.  The keywords are:
 +
 
 +
 
 +
        eol=c          - specifies an end of line comment character
 +
                          (just one)
 +
        skip=n          - specifies the number of lines to skip at the
 +
                          beginning of the file.
 +
        delims=xxx      - specifies a delimiter set.  This replaces the
 +
                          default delimiter set of space and tab.
 +
        tokens=x,y,m-n  - specifies which tokens from each line are to
 +
                          be passed to the for body for each iteration.
 +
                          This will cause additional variable names to
 +
                          be allocated.  The m-n form is a range,
 +
                          specifying the mth through the nth tokens.  If
 +
                          the last character in the tokens= string is an
 +
                          asterisk, then an additional variable is
 +
                          allocated and receives the remaining text on
 +
                          the line after the last token parsed.
 +
        usebackq        - specifies that the new semantics are in force,
 +
                          where a back quoted string is executed as a
 +
                          command and a single quoted string is a
 +
                          literal string command and allows the use of
 +
                          double quotes to quote file names in
 +
                          filenameset.
 +
 
 +
    Some examples might help:
 +
 
 +
FOR /F "eol=; tokens=2,3* delims=, " %i in (myfile.txt) do @echo %i %j %k
 +
 
 +
    would parse each line in myfile.txt, ignoring lines that begin with
 +
    a semicolon, passing the 2nd and 3rd token from each line to the for
 +
    body, with tokens delimited by commas and/or spaces.  Notice the for
 +
    body statements reference %i to get the 2nd token, %j to get the
 +
    3rd token, and %k to get all remaining tokens after the 3rd.  For
 +
    file names that contain spaces, you need to quote the filenames with
 +
    double quotes.  In order to use double quotes in this manner, you also
 +
    need to use the usebackq option, otherwise the double quotes will be
 +
    interpreted as defining a literal string to parse.
 +
 
 +
    %i is explicitly declared in the for statement and the %j and %k
 +
    are implicitly declared via the tokens= option.  You can specify up
 +
    to 26 tokens via the tokens= line, provided it does not cause an
 +
    attempt to declare a variable higher than the letter 'z' or 'Z'.
 +
    Remember, FOR variables are single-letter, case sensitive, global,
 +
    and you can't have more than 52 total active at any one time.
 +
 
 +
    You can also use the FOR /F parsing logic on an immediate string, by
 +
    making the filenameset between the parenthesis a quoted string,
 +
    using single quote characters.  It will be treated as a single line
 +
    of input from a file and parsed.
 +
 
 +
    Finally, you can use the FOR /F command to parse the output of a
 +
    command.  You do this by making the filenameset between the
 +
    parenthesis a back quoted string.  It will be treated as a command
 +
    line, which is passed to a child CMD.EXE and the output is captured
 +
    into memory and parsed as if it was a file.  So the following
 +
    example:
 +
 
 +
      FOR /F "usebackq delims==" %i IN (`set`) DO @echo %i
 +
 
 +
    would enumerate the environment variable names in the current
 +
    environment.
 +
 
 +
In addition, substitution of FOR variable references has been enhanced.
 +
You can now use the following optional syntax:
 +
 
 +
 
 +
    %~I        - expands %I removing any surrounding quotes (")
 +
    %~fI        - expands %I to a fully qualified path name
 +
    %~dI        - expands %I to a drive letter only
 +
    %~pI        - expands %I to a path only
 +
    %~nI        - expands %I to a file name only
 +
    %~xI        - expands %I to a file extension only
 +
    %~sI        - expanded path contains short names only
 +
    %~aI        - expands %I to file attributes of file
 +
    %~tI        - expands %I to date/time of file
 +
    %~zI        - expands %I to size of file
 +
    %~$PATH:I  - searches the directories listed in the PATH
 +
                  environment variable and expands %I to the
 +
                  fully qualified name of the first one found.
 +
                  If the environment variable name is not
 +
                  defined or the file is not found by the
 +
                  search, then this modifier expands to the
 +
                  empty string
 +
 
 +
The modifiers can be combined to get compound results:
 +
 
 +
    %~dpI      - expands %I to a drive letter and path only
 +
    %~nxI      - expands %I to a file name and extension only
 +
    %~fsI      - expands %I to a full path name with short names only
 +
    %~dp$PATH:I - searches the directories listed in the PATH
 +
                  environment variable for %I and expands to the
 +
                  drive letter and path of the first one found.
 +
    %~ftzaI    - expands %I to a DIR like output line
 +
 
 +
In the above examples %I and PATH can be replaced by other valid
 +
values.  The %~ syntax is terminated by a valid FOR variable name.
 +
Picking upper case variable names like %I makes it more readable and
 +
avoids confusion with the modifiers, which are not case sensitive.
 
</code>
 
</code>
  

Version vom 18. Juni 2009, 17:15 Uhr

cmd

Einfach ein paar Notizen

Löschen mehrerer Ordner gleichzeitig

zuerst eine 'Ausführungsliste' erstellen

dir /AD /B | find "14.06.2009" > dellist.txt


liste testen

for /F "delims=" %I in (dellist.txt) do @Echo %I


nun die Ausführungsliste abarbeiten

for /F "delims=" %I in (dellist.txt) do rmdir /S /Q "%I"




DOS Befehle

rmdir

Removes (deletes) a directory.

RD, RMDIR [/S] [/Q] [drive:]path

/S    Removes all directories and files in the specified directory
      in addition to the directory itself.  Used to remove a directory
      tree.

/Q    Quiet mode, do not ask if ok to remove a directory tree with /S

dir

Displays a list of files and subdirectories in a directory.

DIR [drive:][path][filename] [/A[[:]attributes]] [/B] [/C] [/D] [/L] [/N]
    [/O[[:]sortorder]] [/P] [/Q] [/S] [/T[[:]timefield]] [/W] [/X] [/4]

  [drive:][path][filename]
             Specifies drive, directory, and/or files to list.

  /A          Displays files with specified attributes.
  attributes   D  Directories                R  Read-only files
               H  Hidden files               A  Files ready for archiving
               S  System files               -  Prefix meaning not
  /B          Uses bare format (no heading information or summary).
  /C          Display the thousand separator in file sizes.  This is the
              default.  Use /-C to disable display of separator.
  /D          Same as wide but files are list sorted by column.
  /L          Uses lowercase.
  /N          New long list format where filenames are on the far right.
  /O          List by files in sorted order.
  sortorder    N  By name (alphabetic)       S  By size (smallest first)
               E  By extension (alphabetic)  D  By date/time (oldest first)
               G  Group directories first    -  Prefix to reverse order
  /P          Pauses after each screenful of information.
  /Q          Display the owner of the file.
  /S          Displays files in specified directory and all subdirectories.
  /T          Controls which time field displayed or used for sorting
  timefield    C  Creation
               A  Last Access
               W  Last Written
  /W          Uses wide list format.
  /X          This displays the short names generated for non-8dot3 file
              names.  The format is that of /N with the short name inserted
              before the long name. If no short name is present, blanks are
              displayed in its place.
  /4          Displays four-digit years

Switches may be preset in the DIRCMD environment variable.  Override
preset switches by prefixing any switch with - (hyphen)--for example, /-W.

find

Searches for a text string in a file or files.

FIND [/V] [/C] [/N] [/I] [/OFF[LINE]] "string" [[drive:][path]filename[ ...]]

  /V         Displays all lines NOT containing the specified string.
  /C         Displays only the count of lines containing the string.
  /N         Displays line numbers with the displayed lines.
  /I         Ignores the case of characters when searching for the string.
  /OFF[LINE] Do not skip files with offline attribute set.
  "string"   Specifies the text string to find.
  [drive:][path]filename
             Specifies a file or files to search.

If a path is not specified, FIND searches the text typed at the prompt or piped from another command.

for

P:\Cobian_Backup\Claudio>for /?

Runs a specified command for each file in a set of files.

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

 %variable  Specifies a single letter replaceable parameter.
 (set)      Specifies a set of one or more files.  Wildcards may be used.
 command    Specifies the command to carry out for each file.
 command-parameters
            Specifies parameters or switches for the specified command.

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

If Command Extensions are enabled, the following additional forms of the FOR command are supported:

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

   If set contains wildcards, then specifies to match against directory
   names instead of file names.

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

   Walks the directory tree rooted at [drive:]path, executing the FOR
   statement in each directory of the tree.  If no directory
   specification is specified after /R then the current directory is
   assumed.  If set is just a single period (.) character then it
   will just enumerate the directory tree.

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

   The set is a sequence of numbers from start to end, by step amount.
   So (1,1,5) would generate the sequence 1 2 3 4 5 and (5,-1,1) would
   generate the sequence (5 4 3 2 1)

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 usebackq option present:

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]

   filenameset is one or more file names.  Each file is opened, read
   and processed before going on to the next file in filenameset.
   Processing consists of reading in the file, breaking it up into
   individual lines of text and then parsing each line into zero or
   more tokens.  The body of the for loop is then called with the
   variable value(s) set to the found token string(s).  By default, /F
   passes the first blank separated token from each line of each file.
   Blank lines are skipped.  You can override the default parsing
   behavior by specifying the optional "options" parameter.  This
   is a quoted string which contains one or more keywords to specify
   different parsing options.  The keywords are:


       eol=c           - specifies an end of line comment character
                         (just one)
       skip=n          - specifies the number of lines to skip at the
                         beginning of the file.
       delims=xxx      - specifies a delimiter set.  This replaces the
                         default delimiter set of space and tab.
       tokens=x,y,m-n  - specifies which tokens from each line are to
                         be passed to the for body for each iteration.
                         This will cause additional variable names to
                         be allocated.  The m-n form is a range,
                         specifying the mth through the nth tokens.  If
                         the last character in the tokens= string is an
                         asterisk, then an additional variable is
                         allocated and receives the remaining text on
                         the line after the last token parsed.
       usebackq        - specifies that the new semantics are in force,
                         where a back quoted string is executed as a
                         command and a single quoted string is a
                         literal string command and allows the use of
                         double quotes to quote file names in
                         filenameset.
   Some examples might help:

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

   would parse each line in myfile.txt, ignoring lines that begin with
   a semicolon, passing the 2nd and 3rd token from each line to the for
   body, with tokens delimited by commas and/or spaces.  Notice the for
   body statements reference %i to get the 2nd token, %j to get the
   3rd token, and %k to get all remaining tokens after the 3rd.  For
   file names that contain spaces, you need to quote the filenames with
   double quotes.  In order to use double quotes in this manner, you also
   need to use the usebackq option, otherwise the double quotes will be
   interpreted as defining a literal string to parse.
   %i is explicitly declared in the for statement and the %j and %k
   are implicitly declared via the tokens= option.  You can specify up
   to 26 tokens via the tokens= line, provided it does not cause an
   attempt to declare a variable higher than the letter 'z' or 'Z'.
   Remember, FOR variables are single-letter, case sensitive, global,
   and you can't have more than 52 total active at any one time.
   You can also use the FOR /F parsing logic on an immediate string, by
   making the filenameset between the parenthesis a quoted string,
   using single quote characters.  It will be treated as a single line
   of input from a file and parsed.
   Finally, you can use the FOR /F command to parse the output of a
   command.  You do this by making the filenameset between the
   parenthesis a back quoted string.  It will be treated as a command
   line, which is passed to a child CMD.EXE and the output is captured
   into memory and parsed as if it was a file.  So the following
   example:
     FOR /F "usebackq delims==" %i IN (`set`) DO @echo %i
   would enumerate the environment variable names in the current
   environment.

In addition, substitution of FOR variable references has been enhanced. You can now use the following optional syntax:


   %~I         - expands %I removing any surrounding quotes (")
   %~fI        - expands %I to a fully qualified path name
   %~dI        - expands %I to a drive letter only
   %~pI        - expands %I to a path only
   %~nI        - expands %I to a file name only
   %~xI        - expands %I to a file extension only
   %~sI        - expanded path contains short names only
   %~aI        - expands %I to file attributes of file
   %~tI        - expands %I to date/time of file
   %~zI        - expands %I to size of file
   %~$PATH:I   - searches the directories listed in the PATH
                  environment variable and expands %I to the
                  fully qualified name of the first one found.
                  If the environment variable name is not
                  defined or the file is not found by the
                  search, then this modifier expands to the
                  empty string

The modifiers can be combined to get compound results:

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

In the above examples %I and PATH can be replaced by other valid values. The %~ syntax is terminated by a valid FOR variable name. Picking upper case variable names like %I makes it more readable and avoids confusion with the modifiers, which are not case sensitive.

echo

all

P:\Cobian_Backup\Claudio>help

For more information on a specific command, type HELP command-name ASSOC Displays or modifies file extension associations. AT Schedules commands and programs to run on a computer. ATTRIB Displays or changes file attributes. BREAK Sets or clears extended CTRL+C checking. CACLS Displays or modifies access control lists (ACLs) of files. CALL Calls one batch program from another. CD Displays the name of or changes the current directory. CHCP Displays or sets the active code page number. CHDIR Displays the name of or changes the current directory. CHKDSK Checks a disk and displays a status report. CHKNTFS Displays or modifies the checking of disk at boot time. CLS Clears the screen. CMD Starts a new instance of the Windows command interpreter. COLOR Sets the default console foreground and background colors. COMP Compares the contents of two files or sets of files. COMPACT Displays or alters the compression of files on NTFS partitions. CONVERT Converts FAT volumes to NTFS. You cannot convert the

        current drive.

COPY Copies one or more files to another location. DATE Displays or sets the date. DEL Deletes one or more files. DIR Displays a list of files and subdirectories in a directory. DISKCOMP Compares the contents of two floppy disks. DISKCOPY Copies the contents of one floppy disk to another. DOSKEY Edits command lines, recalls Windows commands, and creates macros. ECHO Displays messages, or turns command echoing on or off. ENDLOCAL Ends localization of environment changes in a batch file. ERASE Deletes one or more files. EXIT Quits the CMD.EXE program (command interpreter). FC Compares two files or sets of files, and displays the differences

        between them.

FIND Searches for a text string in a file or files. FINDSTR Searches for strings in files. FOR Runs a specified command for each file in a set of files. FORMAT Formats a disk for use with Windows. FTYPE Displays or modifies file types used in file extension associations. GOTO Directs the Windows command interpreter to a labeled line in a

        batch program.

GRAFTABL Enables Windows to display an extended character set in graphics

        mode.

HELP Provides Help information for Windows commands. IF Performs conditional processing in batch programs. LABEL Creates, changes, or deletes the volume label of a disk. MD Creates a directory. MKDIR Creates a directory. MODE Configures a system device. MORE Displays output one screen at a time. MOVE Moves one or more files from one directory to another directory. PATH Displays or sets a search path for executable files. PAUSE Suspends processing of a batch file and displays a message. POPD Restores the previous value of the current directory saved by PUSHD. PRINT Prints a text file. PROMPT Changes the Windows command prompt. PUSHD Saves the current directory then changes it. RD Removes a directory. RECOVER Recovers readable information from a bad or defective disk. REM Records comments (remarks) in batch files or CONFIG.SYS. REN Renames a file or files. RENAME Renames a file or files. REPLACE Replaces files. RMDIR Removes a directory. SET Displays, sets, or removes Windows environment variables. SETLOCAL Begins localization of environment changes in a batch file. SHIFT Shifts the position of replaceable parameters in batch files. SORT Sorts input. START Starts a separate window to run a specified program or command. SUBST Associates a path with a drive letter. TIME Displays or sets the system time. TITLE Sets the window title for a CMD.EXE session. TREE Graphically displays the directory structure of a drive or path. TYPE Displays the contents of a text file. VER Displays the Windows version. VERIFY Tells Windows whether to verify that your files are written

        correctly to a disk.

VOL Displays a disk volume label and serial number. XCOPY Copies files and directory trees.