Forfilesの使用法と例



Forfiles Usage Examples



  • 現在のディレクトリをトラバースして、すべてのファイル名を表示します
forfiles /c 'cmd /c echo @file' // /c indicates that the following specification will be executed, double quotes must be used
  • 現在のディレクトリをトラバースして、すべてのファイルのフルパスを表示します
forfiles /c 'cmd /c echo @path' @path indicates file path variable
  • 指定されたディレクトリをトラバースして、すべてのファイル名を表示します
forfiles /p d:folder /c 'cmd /c echo @file' // /p is specified after the directory, in order to prevent spaces in the directory, it is best to add double quotation marks ''
  • 指定されたディレクトリ(サブディレクトリを含む)をトラバースし、すべてのファイル名を表示します
forfiles /p d:folder /s /c 'cmd /c echo @file' // /s means traversing subdirectories
  • 指定されたディレクトリ(サブディレクトリを含む)で指定されたサフィックス名を持つファイルをトラバースし、すべてのファイル名を表示します
forfiles /p d:folder /s /M *.log /c 'cmd /c echo @file' // /M specifies the mask of the search file, which is a wildcard
  • 指定されたディレクトリ(サブディレクトリを含む)内の指定されたサフィックス名でファイルをトラバースし、変更時刻が表示されてから何日後かを指定します
forfiles /p d:folder /s /M *.log /d -4 /c 'cmd /c echo @file' // /d -4, specify files that are separated from the current time and above
  • 指定されたディレクトリをトラバースして、指定された日付より前のファイルを表示します
forfiles /p d:folder /d -2018/02/03 /c 'cmd /c echo @file' // /d -2018/02/03 Limits files before 2018/02/03
  • 指定されたディレクトリをトラバースして、指定された日付以降のファイルを表示します
forfiles /p d:folder /d +2018/02/03 /c 'cmd /c echo @file' // /d -2018/02/03 Limits files before 2018/02/03
  • 指定されたディレクトリをトラバースして、指定された日付以降のファイルを表示し、削除します
forfiles /p d:folder /d +2018/02/03 /c 'cmd /c del /f /q @path' // /c del /f /q deletes the @path path file, /f is forcibly deleting read-only files, /q is quiet mode, ie no prompt to confirm deletion