forfiles

ファイル (または、ファイルのセット) を選んで、そのファイル上のコマンドを実行します。

ForFiles - 選択したファイルに対してコマンドを実行


forfiles

  • C:\Windows\system32\forfiles.exe /?

Output:


FORFILES [/P パス名] [/M 検索マスク] [/S]
         [/C コマンド] [/D [+ | -] {yyyy/MM/dd | dd}]

説明:
    ファイル (または、ファイルのセット) を選んで、そのファイル上の
    コマンドを実行します。これはバッチ ジョブの使用に便利です。

パラメーター一覧:
    /P    パス名        検索を開始するパスを示します。
                        既定のフォルダーは現在実行中の
                        ディレクトリ (.) です。

    /M    検索マスク    検索マスクによってファイルを検索します。
                        既定の検索マスクは '*' です。

    /S                  サブディレクトリに対しても処理を行うように forfiles に
                        指示します (例: "DIR /S")。

    /C    コマンド      各ファイルの実行するコマンドを示します。
                        コマンドの文字列は二重引用符で囲んでくだ
                        さい。

                        既定のコマンドは "cmd /c echo @file" です。

                        次の変数をコマンドの文字列に使用することができ
                        ます:
                        @file    - フィルの名前を返します。
                        @fname   - 拡張子なしのファイル名を
                                   返します。
                        @ext     - ファイルの拡張子だけを返し
                                   ます。
                        @path    - ファイルの完全なパスを返します。
                        @relpath - ファイルの相対パスを返し
                                   ます。
                        @isdir   - ファイルの種類がディレクトリの場合
"TRUE"を、ファイルの場合は
                                   "FALSE" を返します。
                        @fsize   - ファイルのサイズをバイトで返し
                                   ます。
                        @fdate   - ファイルの最終更新日を返し
                                   ます。
                        @ftime   - ファイルの最終更新時刻を返し
                                   ます。

                        コマンド ラインに特殊文字を使用する場合は、
                        文字を 16 進数コードで 0xHH 形式で (例:
                        タブは 0x09) 指定してください。CMD.EXE の
                        内部コマンドの前には "cmd /c" が必要
                        です。

    /D    日付          最終更新日が指定された日かもしくはそれ
                        以降 (+)、または指定された日またはそれ
                        以前 (-) であるファイルを "yyyy/MM/dd" 形式を使っ
                        て選択します。または、最終更新日が現在
                        の日にちより "dd" 日あと、もしくは "dd"                        前であるファイルを選択します。有効な "dd"
                        値は 0 から 32768 の間です。
                        指定がない場合は、"+" が既定で使用さ
                        れます。
    /?                  ヘルプまたは使用法を表示します。

:
    FORFILES /?
    FORFILES 
    FORFILES /P C:\WINDOWS /S /M DNS*.*
    FORFILES /S /M *.txt /C "cmd /c type @file | more"
    FORFILES /P C:\ /S /M *.bat
    FORFILES /D -30 /M *.exe
             /C "cmd /c echo @path 0x09 was changed 30 days ago"
    FORFILES /D 2006/1/2
             /C "cmd /c echo @fname is new since Jan 1st 2001"
    FORFILES /D +2006/1/2 /C "cmd /c echo @fname is new today"
    FORFILES /M *.exe /D +1
    FORFILES /S /M *.doc /C "cmd /c echo @fsize"
    FORFILES /M *.txt /C "cmd /c if @isdir==FALSE notepad.exe @file"

FORFILES [/P pathname] [/M searchmask] [/S]
         [/C command] [/D [+ | -] {MM/dd/yyyy | dd}]

Description:
    Selects a file (or set of files) and executes a
    command on that file. This is helpful for batch jobs.

Parameter List:
    /P    pathname      Indicates the path to start searching.
                        The default folder is the current working
                        directory (.).

    /M    searchmask    Searches files according to a searchmask.
                        The default searchmask is '*' .

    /S                  Instructs forfiles to recurse into
                        subdirectories. Like "DIR /S".

    /C    command       Indicates the command to execute for each file.
                        Command strings should be wrapped in double
                        quotes.

                        The default command is "cmd /c echo @file".

                        The following variables can be used in the
                        command string:
                        @file    - returns the name of the file.
                        @fname   - returns the file name without
                                   extension.
                        @ext     - returns only the extension of the
                                   file.
                        @path    - returns the full path of the file.
                        @relpath - returns the relative path of the
                                   file.
                        @isdir   - returns "TRUE" if a file type is
                                   a directory, and "FALSE" for files.
                        @fsize   - returns the size of the file in
                                   bytes.
                        @fdate   - returns the last modified date of the
                                   file.
                        @ftime   - returns the last modified time of the
                                   file.

                        To include special characters in the command
                        line, use the hexadecimal code for the character
                        in 0xHH format (ex. 0x09 for tab). Internal
                        CMD.exe commands should be preceded with
                        "cmd /c".

    /D    date          Selects files with a last modified date greater
                        than or equal to (+), or less than or equal to
                        (-), the specified date using the
                        "MM/dd/yyyy" format; or selects files with a
                        last modified date greater than or equal to (+)
                        the current date plus "dd" days, or less than or
                        equal to (-) the current date minus "dd" days. A
                        valid "dd" number of days can be any number in
                        the range of 0 - 32768.
                        "+" is taken as default sign if not specified.

    /?                  Displays this help message.

Examples:
    FORFILES /?
    FORFILES 
    FORFILES /P C:\WINDOWS /S /M DNS*.*
    FORFILES /S /M *.txt /C "cmd /c type @file | more"
    FORFILES /P C:\ /S /M *.bat
    FORFILES /D -30 /M *.exe
             /C "cmd /c echo @path 0x09 was changed 30 days ago"
    FORFILES /D 1/20/2006
             /C "cmd /c echo @fname is new since Jan 1st 2001"
    FORFILES /D +1/20/2006 /C "cmd /c echo @fname is new today"
    FORFILES /M *.exe /D +1
    FORFILES /S /M *.doc /C "cmd /c echo @fsize"
    FORFILES /M *.txt /C "cmd /c if @isdir==FALSE notepad.exe @file"

Return Code: 0


C:\Windows\system32\forfiles.exe
c:\>ver
Microsoft Windows [Version 10.0.19045.2075]
FileInfo
File Size52224bytes
Creation Time2019/12/07 18:09:37
LastWrite Time2019/12/07 18:09:37
ProductVersion10.0.19041.1889
FileVersion10.0.19041.1889 (WinBuild.160101.0800)
HashValue
MD59bb67aea5e26cb136f23f29cc48d6b9e
SHA1cabee28f7368aae1ac23f0713e2c330f96af2062
SHA224376a0f93b167ad5c334c0514ce96ec2e71be6806e4c1a676401274f7
SHA2569b4886f187489a190bb2c412772c1998539f086c63a4cfd72ff3b107cbc21907
SHA38452831636afec50a2f6fc4cbf7766f1831d513707653896695036cccf5f51e3ed4c8cf9fe299dea60634175d92c9bfb7c
SHA512ac1ea7be97cadce0abf3b581a97b32cceecdc5e7015704ef6a08e33d47f928aab4758df61efb9856057c09d31629ea080f9525b199daebaa4b945338086411bb
Built with Hugo
テーマ StackJimmy によって設計されています。