Forrest logo
back to the forfiles tool

forfiles:tldr:1e070

forfiles: Run the specified command for each file.
$ forfiles /c "${command}"
try on your machine

The command "forfiles /c "${command}"" is used in command line scripting for batch processing of files based on certain criteria.

Here's a breakdown of the components:

  1. "forfiles" is a Windows command line utility that iterates through files in a specified directory tree and executes a command on them.
  2. "/c" is an option for the "forfiles" command, indicating that the following string should be treated as a command to execute on each selected file.
  3. "${command}" is a placeholder or variable to be replaced with an actual command or a series of commands. This is where you would specify what action or actions you want to perform on each file.

To illustrate how this command is used, here's an example:

Let's say you want to delete all files in a specific directory that haven't been modified in the last 30 days. You could use the following command:

forfiles /c "if @isdir==FALSE if @fdate < 30/01/2022 del @file"

In this example, the "${command}" is replaced with the conditional command "if @isdir==FALSE if @fdate < 30/01/2022 del @file". This command checks if the file is not a directory and if its modification date is earlier than 30th January 2022. If both conditions are met, the file is deleted using the "del" command.

Note: The syntax and usage of the "forfiles" command might vary slightly depending on the Windows operating system you are using.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the forfiles tool