Welcome! Log In

it exists 2 versions of forfiles ... one include in Windows 8 that used "/" for parameters and the standalone version that you can download in my forum that use "-" for parameters

Under Windows 2008 serveur try this command : FORFILES.EXE /?

Suppression de sauvegardes différentielles ou fichiers plus anciens que 15j :

PushD "\\monserveur\sauvegarde" &&(
c:\forfiles.exe -s -m*diff*.bkf -d-15 /c "cmd /c del @file"
) & PopD

PushD "\\monserveur\sauvegarde" &&(
c:\forfiles.exe -s -m*.* -d-15 /c "cmd /c del @file"
) & PopD




Mis à jour: avril 2007

S'applique à: Windows Server 2008, Windows Vista

Selects and executes a command on a file or set of files. This command is useful for batch processing.

For examples of how to use this command, see Examples.

forfiles [/p <Path>] [/m <SearchMask>] [/s] [/c "<Command>"] [/d [{+|-}][{<Date>|<Days>}]]


Parameter Description

/p <Path>

Specifies the path from which to start the search. By default, searching starts in the current working directory.

/m <SearchMask>

Searches files according to the specified search mask. The default search mask is *.*.


Instructs the forfiles command to search into subdirectories recursively.

/c "<Command>"

Runs the specified command on each file. Command strings should be enclosed in quotation marks. The default command is "cmd /c echo @file".

/d [{+|-}][{<Date>|<Days>}]

Selects files with a last modified date within the specified time frame.

* Selects files with a last modified date later than or equal to (+) or earlier than or equal to (-) the specified date, where Date is in the format MM/DD/YYYY.

* Selects files with a last modified date later than or equal to (+) the current date plus the number of days specified, or earlier than or equal to (-) the current date minus the number of days specified.

* Valid values for Days include any number in the range 0–32,768. If no sign is specified, + is used by default.


Displays help at the command prompt.

* Forfiles is most commonly used in batch files.

* Forfiles /s is similar to dir /s.

* You can use the following variables in the command string as specified by the /c command-line option.

Variable Description


File name.


File name without extension.


File name extension.


Full path of the file.


Relative path of the file.


Evaluates to TRUE if a file type is a directory. Otherwise, this variable evaluates to FALSE.


File size, in bytes.


Last modified date stamp on the file.


Last modified time stamp on the file.
* With forfiles, you can run a command on or pass arguments to multiple files. For example, you could run the type command on all files in a tree with the .txt file name extension. Or you could execute every batch file (*.bat) on drive C, with the file name "Myinput.txt" as the first argument.

* With forfiles, you can do any of the following:

o Select files by an absolute date or a relative date by using the /d parameter.

o Build an archive tree of files by using variables such as @FSIZEand @FDATE.

o Differentiate files from directories by using the @ISDIRvariable.

o Include special characters in the command line by using the hexadecimal code for the character, in 0xHH format (for example, 0x09 for a tab).

* Forfiles works by implementing the recurse subdirectories flag on tools that are designed to process only a single file.


To list all of the batch files on drive C, type:

forfiles /p c:\ /s /m *.bat /c "cmd /c echo @file is a batch file"

To list all of the directories on drive C, type:

forfiles /p c:\ /s /m *.* /c "cmd /c if @isdir==true echo @file is a directory"

To list all of the files in the current directory that are at least one year old, type:

forfiles /s /m *.* /d -365 /c "cmd /c echo @file is at least one year old."

To display the text "File is outdated" for each of the files in the current directory that are older than January 1, 2007, type:

forfiles /s /m *.* /d -01/01/2007 /c "cmd /c echo @file is outdated."

To list the file name extensions of all the files in the current directory in column format, and add a tab before the extension, type:

forfiles /s /m *.* /c "cmd /c echo The extension of @file is 0x09@ext"

Edited 2 time(s). Last edit at 12/03/2015 06:37PM by iznogoud.
commande forfiles pour nettoyer des sauvegardes SQL .. ici on conserve seulement 15j de sauvegarde :

With FORFILES.EXE (downloadable version):

c:\FORFILES.exe -p"D:\SAUVEGARDESQL" -s -m*.bak -d-15 -c"CMD /C del @FILE"
c:\FORFILES.exe -p"D:\SAUVEGARDESQL" -s -m*.txt -d-15 -c"CMD /C del @FILE"
c:\FORFILES.exe -p"D:\SAUVEGARDESQL" -s -m*.trn -d-15 -c"CMD /C del @FILE"

With FORFILES.EXE included in WINDOWS 2008:

FORFILES.exe /p "S:\SQL-BACKUP" /s /m *.bak /d -30 -c "CMD /C del @FILE"
FORFILES.exe /p "S:\SQL-BACKUP" /s /m *.txt /d -30 -c "CMD /C del @FILE"
FORFILES.exe /p "S:\SQL-BACKUP" /s /m *.trn /d -30 -c "CMD /C del @FILE"

With FORFILES.EXE (downloadable version):

FORFILES et 7ZIP.EXE (compress backup sql files / BAK using forfiles.exe):

c:\FORFILES.exe -p"C:\BACKUP_SQL" -m*.bak -s -c"CMD /C C:\Progra~1\7-Zip\7z.exe a @FILE.7z @FILE"

older than 3 days ...

c:\FORFILES.exe -p"C:\BACKUP_SQL" -m*.bak -s -d-3 /c"CMD /C C:\Progra~1\7-Zip\7z.exe a @FILE.7z @FILE"

then delete oldest ...

c:\FORFILES.exe -p"C:\BACKUP_SQL" -m*.7z -d-30 -s -c"CMD /C del @FILE"

Delete folders and subfolders:

ForFiles /P D:\MYFOLDER /D -35 /C “CMD /C if @ISDIR==TRUE echo RD /Q @FILE &RD /Q /S @FILE”

Edited 4 time(s). Last edit at 07/29/2014 03:45PM by iznogoud.
Forfiles - TechNet - Microsoft
Forfiles. Sélectionne et exécute une commande sur un fichier ou un ensemble de ... Indique à la commande forfiles à rechercher dans les sous-répertoires de ...
Forfiles - TechNet - Microsoft
technet.microsoft.com/en-us/library/cc753551.aspx‎Traduire cette page
17 avr. 2012 - Instructs the forfiles command to search into subdirectories recursively. /c "<Command>". Runs the specified command on each file. Command ...
Forfiles - Batch process multiple files | SS64.com
ss64.com/nt/forfiles.html‎Traduire cette page
FORFILES.exe (Native command in Vista/Windows7/2008, via Resource Kit for XP). Select a file (or set of files) and execute a command on each file.
FORFILES : un outil en ligne de commande Windows pour gérer ...
30 mai 2012 - Forfiles est une commande native native sous Windows 2008 R2 qui permet d'exécuter une commande les fichiers ne répondant qu'à des ...
forfiles dos and windows command lne help - Computer Hope
www.computerhope.com/forfiles.htm‎Traduire cette page
Help with the forfiles dos and windows command line command.
forfiles - Supprimer les fichiers vieux de 3 jours - Forum du club ...
www.developpez.net › ... › Windows › Scripts/Batch‎
29 juin 2007 - forfiles - Supprimer les fichiers vieux de 3 jours Scripts/Batch.
[Batch] forfiles vers disque réseau
30 mai 2013
Traitement erreur de la command forfiles
19 mai 2011
Autres résultats sur www.developpez.net
[batch]forfiles et espace dans nom de fichier - Comment Ça Marche
10 nov. 2009 - ok je tenterai ca ce soir merci :) je te tiens au jus !
Windows Commands: forfiles
windows.commands.com/forfiles‎Traduire cette page
Information about the Windows command: forfiles. ... Delete the testfile if it is is 5 days old or older: C:\> forfiles /m testfile.txt /c "cmd /c Del testfile.txt " /d -5 Find ...
FORFILES v 1.1 - by Emmanuel Boersma - 4/98 - forum.gpit.fr
forum.gpit.fr › ... › FICHIERS/FILES/DOWNLOADS‎
FORFILES v 1.1 - by Emmanuel Boersma - 4/98 Syntax : FORFILES [-pPath] [-mSearch Mask] [-ccommand] [-dDDMMYY] [-s] -pPath Path where to start ...
Forfiles command line tool | Sysadmins Knowledge Base
www.sysads.co.uk/2013/.../forfiles-command-line-too...‎Traduire cette page
5 janv. 2013 - Forfiles is a great windows command line tool and it comes in handy when you need to clean out older files on your machine or server and able ...
Need to get ouput of file list which are deleted through forfiles ...
community.spiceworks.com › Windows‎Traduire cette page
31 août 2012 - 25 messages - ‎4 auteurs
I'm having a forfile script to delete files older than X days. It is working perfectly. But i need to get the oup... | 49 replies | Microsoft Windows ...
Forfiles Batch Script (Escaping @ character) - Stack Overflow
stackoverflow.com/.../forfiles-batch-script-escaping-c...‎Traduire cette page
24 juin 2009 - I'm working on a batch script that will let me delete files older then a ... I had the same problem until I removed the quotation marks around the ...
Using forfiles with multiple file types for search mask? - Stack Overflow
stackoverflow.com/.../using-forfiles-with-multiple-file...‎Traduire cette page
30 juil. 2012 - Following command works fine with one type of files , forfiles -p ... Not as nice as I hoped for but this oneliner can help out. Notice however that ...
Suppress FORFILES "no files found" error - Stack Overflow
stackoverflow.com/.../suppress-forfiles-no-files-found...‎Traduire cette page
30 mai 2013 - I'm working with a batch file to delete archived documents older than ... This should solve that issue: @echo off Echo Deleting files older than 14 ...
Forfiles.exe: deleting files - CodeProject
www.codeproject.com › ... › General‎Traduire cette page
20 févr. 2012 - Batch file for deleting files automatically using ForFiles.exe.; Author: yudi19872001; Updated: 20 Feb 2012; Section: Files and Folders; Chapter: ...
ForFiles - delete old files, etc. | Windows Problem Solver
winhlp.com › Forums › Software › Other software‎Traduire cette page
16 oct. 2007 - Introduction. A few Windows resource kits contained the sometimes very useful tool: forfiles.exe. It can be used to process large numbers of files ...
Forfiles Script Batch (Escaping caractère @) - assistance technique
Je travaille sur un script de commandes qui me permettra de supprimer les fichiers anciens, puis une période déterminée à l'aide de forfiles. Pour l'instant, je ...
galatea.meccahosting.com/~a000769d/.../forfiles.html‎Traduire cette page
syntax FORFILES [-pPath] [-s] [-dDate] [-mMask] [-cCommand] key -pPath : Path to search default=current folder -s : Recurse into sub-folders -dDate : This can be ...
www.tekweb.dk › Home › Commands AM › Batch F‎Traduire cette page
Home > Commands A-M > Batch F. FORFILES. Description | Syntax | Parameters | Switches | Related | Notes | Examples | Errorlevels | Availability.
www.ipass.net/davesisk/oont_download_forfiles.htm‎Traduire cette page
FORFILES v1.1: This NT command's functionality somewhat resembles the UNIX find command. It can be used to select files in a particular subdirectory ...
Use Forfiles To Process Files Based On Age | Ghacks
www.ghacks.net › Software‎Traduire cette page
De Martin Brinkmann - Dans 887 cercles Google+
5 août 2010 - The forfiles command can be coupled with processing options to delete those files, or create a list of all files that match the filters. Lets take a ...
Batch changer extension dans FORFILES + commande - Tom's Guide
www.tomsguide.fr › Solutions › Programmation‎
Hello J'aimerais exécuter une commande (conversion vidéo avec ffmpeg) sur l'ensemble des fichiers MOV de mon répertoire. J'ai donc fait un .bat et je suis ...
Forfile:- Delete files older than X days old. | vabsnanoti
vabsnanoti.wordpress.com/.../forfile-delete-files-older...‎Traduire cette page
22 févr. 2012 - ForFiles will process a command against files and folders that match your criteria. It allows you to set wildcards, pick only folders, or only ...
Knowledge of the Day: FORFILES
knowledgeoftheday001.blogspot.com/.../forfiles.html‎Traduire cette page
22 mai 2013 - Forfiles is a powerful Windows command utility that a Windows system Administrator need to know for his daily Administration works.
Effacer automatiquement dossiers de plus de x jours ? (Clubic.com)
8 juil. 2010 - j'ai besoin d'aide pour effacer automatiquement des dossiers (tous les 30jours) je pense que forfiles peut résoudre mon problème mais j'ai un ...
Batch :: Programmation forfiles
batch.xoo.it › [Batch] › >> Aide Programmation‎
23 mai 2013 - 8 messages - ‎2 auteurs
pour info je ne suis pas spécialement attaché a FORFILES. Par avance merci pour votre aide. Mathias Point(s): 1 Évaluer: Plus - Moins.
Windows, supprimer des élèments plus vieux que x jours | On Da Fl0w
28 févr. 2011 - forfiles.exe /p "D:Mon_Repertoire" /s /m *.* /d -15 /c "cmd /c del /q @path". Voici le man du binaire forfiles : FORFILES [/P nom_chemin_accès] ...
Did You Restart?: Forfiles to manipulate files based on date
didyourestart.blogspot.com/.../forfiles-to-manipulate-...‎Traduire cette page
5 août 2011 - Nothing new here... You can use Forfiles to manipulate files based on their date. /P Path to search /M SearchMask /S Subdirectories
FORFILES, for your fancier batch file enumeration needs - The Old ...
blogs.msdn.com › The Old New Thing‎Traduire cette page
3 août 2012 - For your fancy recursive file operations, there's a tool called FORFILES which iterates through the contents of a directory (recursively if ...
windows xp - Why does the command forfiles list files that are not a ...
superuser.com/.../why-does-the-command-forfiles-list...‎Traduire cette page
18 sept. 2012 - The version of forfiles I have reads as follows FORFILES v 1.1 - emmanubo@microsoft.com - 4/98 . The batch file is being run on Windows XP.
forfiles : Forum Scripting Microsoft
25 août 2008 - 6 messages - ‎3 auteurs
Bonjour, Peut on lancer des vbs à chaque ficher détecté par un forfile dans un bat ? Dans un répertoire D:\EDITION\A_TRAITER\ j'ai des ...
Windows forfiles command tips - Burleson Oracle Consulting
www.dba-oracle.com/t_windows_forfiles_command....‎Traduire cette page
29 juil. 2012 - Windows forfiles command tips. ... The forfiles command searches for a given set of files and then performs a specified action on the returned ...
DOS Help: Command forfiles - Petri IT Knowledgebase Forums
www.petri.co.il/forums/showthread.php?t=61775‎Traduire cette page
18 oct. 2012 - 3 messages - ‎2 auteurs
DOS Help: Command forfiles General Scripting. ... What you should add to the Forfiles stament is the If @isDir==FALSE condition. Then it will ...
Batch script FORFILES HELP <SOLVED> - Overclock.net
www.overclock.net › ... › Coding and Programming‎Traduire cette page
30 sept. 2011 - hi guys ive been trying to make a small bat file that removes files from a folder that are older that 2 days. did a bit of googleing and decided to ...
25 août 2008 - Bonjour, Peut on lancer des vbs à chaque ficher détecté par un forfile dans un bat ? Dans un répertoire D:\EDITION\A_TRAITER\ j'ai des ...
Delete Files Older Than x Days - ForFiles.exe - Script Issues ...
www.edugeek.net › ... › Scripts‎Traduire cette page
11 janv. 2011 - 3 messages - ‎2 auteurs
Hi, I'm having a little issue with a batch script that I've managed to create, using information from various posts and forums on the web but can't.
Geek INpact: FORFILES utiliser pour traiter les fichiers en fonction ...
12 avr. 2011 - La commande FORFILES peut être couplé avec les options de traitement pour supprimer ces fichiers, ou créer une liste de tous les fichiers qui ...
Finishing Forfiles | Windows content from Windows IT Pro
windowsitpro.com/windows/finishing-forfiles‎Traduire cette page
26 janv. 2009 - Now that you know the basics of Forfiles (forfiles.exe)—a command-line tool that, like the For command, lets you perform repetitive tasks without ...
Forfiles - move files based on date - keep directory structure ...
ss64.org › Windows CMD Shell‎Traduire cette page
10 oct. 2012 - 4 messages
IF NOT EXIST "Y:\BATS\Pig Pen Archive\.2" MD "Y:\BATS\Pig Pen Archive\.2" forfiles /p "X:\Dir\Pig Pen Archive\.2" /m *.* /d -01/01/2012 /c "cmd ...
Forfiles command not working with autoit - General Help and ...
www.autoitscript.com › ... › General Help and Support‎Traduire cette page
28 janv. 2013 - Forfiles command not working with autoit - posted in General Help and Support: So Im trying to use FORFILES dos command with autoit.
www.gatepoint.ch/.../43f6b004-446d-4fdd-91c5-565...‎Traduire cette page
Forfiles. Selects and executes a command on a file or set of files. This command is useful for batch processing. For examples of how to use this command, see ...
or8.net › Home › Commands AM › Batch F‎Traduire cette page
28 juil. 2003 - Home > Commands A-M > Batch F. FORFILES. Description | Syntax | Parameters | Switches | Related | Notes | Examples | Errorlevels | ...
two forfiles problems - Programming (C++, Delphi, VB/VBS, CMD ...
www.msfn.org/board/.../156053-two-forfiles-proble...‎Traduire cette page
29 mars 2012 - two forfiles problems - posted in Programming (C++, Delphi, VB/VBS, CMD/batch, etc.): Hi, I'm not a programmer, more like a "one liner".
Merrick Chaffer's Blog : Iterating files in DOS using FORFILES.exe
consultingblogs.emc.com/.../iterating-files-in-dos.asp...‎Traduire cette page
12 janv. 2011 - Just came across a nice little command line utility called forfiles.exe. Very useful for batch file scripting, for example you can use this to ...
TUTOS.EU : Purger les anciens fichiers avec forfiles (reference 3196)
Comment effacer simplement avec un .bat les anciens fichiers.
Qu'est-ce que forfiles.exe ? | System Explorer
Nous connaissons 5 variantes de fichier pour forfiles.exe. Cliquez ici pour obtenir plus d'information au sujet de forfiles.exe..
mfpsupport.com - Tips - Forfiles - my favourite command line tool
www.mfpsupport.com/.../forfiles-my-favourite-comm...‎Traduire cette page
1 août 2012 - Forfiles is my favourite addition to the command line. ... As a programmer, without Forfiles, I'd be looking to power up Visual Studio or ...
Forfiles RD /S /Q - Google Groups
24 janv. 2009 - I want to keep today and yesterday this command echos only the daybefore folder, which is want I want FORFILES -pD:/TEST -s -M*.
Command Forfiles - Scribd
www.scribd.com/doc/138920113/Command-Forfiles‎Traduire cette page
5 janv. 2013 - Command Forfiles - Free download as PDF File (.pdf), Text File (.txt) or readfalse online for free.
forfiles - ICT Support Specialist
www.ictsupportspecialist.com/.../206-forfiles?...‎Traduire cette page
Forfiles Selects files in a folder or tree for batch processing. Syntax forfiles [/p Path] [/m SearchMask] [/s] [/c Command] [/d[{+ | -}] [{MM/DD/YYYY | DD}]].

Recherches associées à forfiles
Sorry, only registered users may post in this forum.

Click here to login