Share to: share facebook share twitter share wa share telegram print page

Forfiles

forfiles
Developer(s)Microsoft
Operating systemMicrosoft Windows
TypeCommand
LicenseProprietary commercial software
Websitedocs.microsoft.com/en-us/windows-server/administration/windows-commands/forfiles

forfiles is a computer software utility for Microsoft Windows, which selects files and runs a command on them. File selection criteria include name and last modified date. The command specifier supports some special syntax options. It can be used directly on the command line, or in batch files or other scripts.

The forfiles command was originally provided as an add-on, in the Windows 98,[1] Windows NT[citation needed] and Windows 2000[2] Resource Kits. It became a standard utility with Windows Vista, as part of the new management features.

Usage

The forfiles command has several command-line switches. If no switches or parameters given, it outputs the name of every file in the current directory.

Switches

Switch Argument Meaning
/P pathname The directory (folder) to search for files in. The default is the current directory. UNC paths (\\machine\share) are not accepted.
/M searchmask A glob pattern (wildcard search). Only files whose filename matches the pattern are selected. The file extension is included in the filename; the path (folder name) is not. The pattern must match the entire name, or use wildcards. The default is to match all files.

This option treats glob patterns *.* and * differently. The former will only match files with a dot in their name, while the latter will match even those with no dot or extension. Most DOS/Windows commands will match files with no extension even when given a *.* pattern.

/S (none) Selects matching files in subdirectories. By default, only the single, specified directory is searched.
/C command Execute the given command for each matching file. The command string typically needs to be wrapped in double quotes. See below for the syntax within the command string. The default command is CMD /C ECHO @FILE, which causes the name of each matching file to be output (displayed).
/D date Selects files based on their last modified date. See below for date syntax. By default, files are selected regardless of their date.
/? (none) Displays a help message (brief usage instructions). Suppresses file search/command execution. May not be used with any other switch.

Command syntax

The command string is executed as given, except as noted below.

Sequences of the form 0xFF, where "0x" is literal, and "FF" represents any two-digit hexadecimal number, are replaced with the corresponding single-byte value. This can be used to embed non-printing ASCII characters, or extended ASCII characters.

The sequence \" is replaced with a literal quotation mark ". Using the 0x sequence form described previously, 0x22 can also be used, which additionally hides the " from the command interpreter.

Several variables are provided, to be used in the command as placeholders for the values from each file. Variables are technically not required, but must be used if the command is to vary for each file.

Variable Meaning
@file The name of the matching item, double quoted.
@fname The basename of the matching item (without file extension), double quoted.
@ext The file extension, double quoted, without leading dot. If a file has multiple extensions, only the last is returned. If the file has no extension, a quoted empty string is returned.
@path Full path of the matching item, double quoted, including drive letter, and file extension (if any).
@relpath Path of the matching item, double quoted, and relative to the starting directory (given by /P). Each path begins with a dot and backslash (.\).
@isdir Evaluates to the literal string TRUE if the matching item is a directory, or FALSE if not.
@fsize Size of the matching item, in bytes. Directories report a size of zero.
@fdate Date the file was last modified, in the localized date format of the current user.
@ftime Time the file was last modified, in the localized time format of the current user.

Date syntax

The date switch (/D) selects files based on their last modified date, given a date argument.

The date argument can be given as a literal date, in MM/DD/YYYY format (other date formats are not accepted). Alternatively, the date argument can be given as a number, in which case it is taken to mean an age in days (i.e., the day date days before the present date).

If the date argument begins with a minus (-), only files modified on or before the given date are selected (older file / modified earlier). Otherwise, only files modified on or after the given date are selected (younger files / modified later). An explicit plus (+) may be given, but is the default. Note that both modes select files on the given date. There is no way to select files only on a given date (without also either before or after).

Examples

The following command selects all log files (*.LOG) in the Windows directory 30 days or older, and lists them with their date.

C:\>FORFILES /P C:\Windows /M *.LOG /D -30 /C "CMD /C ECHO @FDATE @FILE"
6/12/2015 "iis7.log"
5/28/2015 "msxml4-KB954430-enu.LOG"
5/28/2015 "msxml4-KB973688-enu.LOG"
5/26/2015 "setuperr.log"

The following command would delete the same files.

C:\>FORFILES /P C:\Windows /M *.LOG /D -30 /C "CMD /C DEL @PATH"

The use of CMD /C is required in the above examples, as both ECHO and DEL are internal to the command processor, rather than external utility programs.

See also

  • cmd.exe – The program implementing the Windows command-line interpreter
  • Foreach loop – The FOR and FORFILES commands both implement a for-each loop
  • find (Unix) – Unix command that finds files by attribute, similar to forfiles
  • find (Windows) – DOS and Windows command that finds text matching a pattern
  • grep – Unix command that finds text matching a pattern, similar to Windows find

References

  • "FORFILES", Microsoft Windows (Computer software), 6.1.7600.16385, Microsoft, 13 July 2009.
  • "Forfiles". TechNet. Microsoft. April 17, 2012. Retrieved 28 April 2016.
  • Simon Sheppard. "FORFILES.exe". SS64. Retrieved 28 April 2016.

Read other articles:

CesaKomuneComune di CesaGereja San Cesario (Cesa, 2014)Lokasi Cesa di Provinsi CasertaNegara ItaliaWilayah CampaniaProvinsiCaserta (CE)Luas[1] • Total2,74 km2 (1,06 sq mi)Ketinggian[2]40 m (130 ft)Populasi (2016)[3] • Total8.496 • Kepadatan3,100/km2 (8,000/sq mi)Zona waktuUTC+1 (CET) • Musim panas (DST)UTC+2 (CEST)Kode pos81030Kode area telepon081Situs webhttp://www.comune.cesa.ce.it C…

HotAlbum mini karya TaeyangDirilis22 Mei 2008Direkam2008GenreR&B, hip hop, PopLabelYG EntertainmentProduserYang Hyun Suk, Teddy, KushKronologi Taeyang Rise(2014)String Module Error: Match not found2014 Hot(2008) Solar(2010)Solar2010 Hot adalah album mini pertama sekaligus album solo pertama dari penyanyi Korea Selatan yang juga anggota grup musik Big Bang, Taeyang. Album ini diterima baik oleh para fans dan kritikus, berhasil memenangkan dua trofi di Korean Music Awards ke-6 untuk Best R…

EssoDidirikan1912; 112 tahun lalu (1912)KantorpusatIrving, Texas, ASProdukMinyak, Bahan bakarIndukExxonMobilSitus webwww.esso.com Esso /ˈɛsoʊ/ adalah sebuah merek dagang dari ExxonMobil dan perusahaan-perusahaan terkaitnya. Nama tersebut adalah sebuah versi fonetik dari inisial Standard Oil sebelum 1911 (SO = Esso),[1] dan menjadi fokus litigasi dan batas regulasi di Amerika Serikat. Pada 1972, perusahaan tersebut kebanyakan digantikan di AS oleh merek Exxon setelah dibawa Humble…

Book by James M. Cain The Butterfly Cover of the first editionAuthorJames M. CainCountryUnited StatesLanguageEnglishGenreIncest literaturePublisherAlfred A. KnopfPublication date1947Media typePrint (hardcover and paperback)ISBN0-679-72323-4 The Butterfly is a hard-boiled novel by author James M. Cain published by Alfred A. Knopf in 1947. The story is set in rural West Virginia in the late 1930s and concerns a mystery surrounding an apparent case of father and daughter incest.[1][…

Vous lisez un « bon article » labellisé en 2009. Le premier serveur web, actuellement au musée du CERN, étiqueté « This machine is a server. DO NOT POWER IT DOWN!! », ce qui signifie : « Cette machine est un serveur. NE PAS L'ÉTEINDRE !! » L'histoire d'Internet remonte au début des années 1960. L'idée d’un réseau informatique, permettant aux utilisateurs de différents ordinateurs de communiquer, se développa par de nombreuses étapes…

Public community college in Littleton, Colorado, United States Arapahoe Community CollegeTypePublic community collegeEstablished1965; 59 years ago (1965)PresidentStephanie J. Fujii[1]Students20,000 (annually)LocationLittleton, Colorado, USA39°36′30″N 105°01′11″W / 39.6084°N 105.0196°W / 39.6084; -105.0196CampusUrban / ruralColors   Purple and WhiteMascotPumasWebsitewww.arapahoe.edu Arapahoe Community College (ACC) is a publi…

Partai Komunis Bohemia dan Moravia Komunistická strana Čech a MoravyKetua umumKateřina KonečnáDibentuk31 Maret 1990Didahului olehPartai Komunis CekoslowakiaKantor pusatPolitických vězňů 9, PrahaWadah pemikirCentrum strategických a teoretických studií KSČMKeanggotaan (2022)20,450IdeologiKomunisme[1][2]Marxisme[3]Eroskeptisisme[4][5][6]Posisi politikSayap kiri hingga kiri jauhAfiliasi EropaPartai Kiri Eropa (pengamat)[7]…

Geisha dilarang untuk menjual seks tetapi keliru menjadi simbol seksualitas Jepang di barat karena pelacur di Jepang memasarkan diri mereka sebagai gadis geisha kepada pria militer Amerika.[1] Seksualitas di Jepang berkembang secara terpisah dari daratan Asia, karena Jepang tidak mengadopsi pandangan Konfusianisme tentang pernikahan, di mana kesucian sangat dihargai. Monogami pada pernikahan sering dianggap kurang penting di Jepang, dan terkadang pria yang sudah menikah mungkin mencari k…

SC FreiburgNama lengkapSport-Club FreiburgJulukanBreisgau-BrasilianerBerdiri30 Mei 1904; 119 tahun lalu (1904-05-30)StadionStadion Europa-ParkFreiburg, Jerman(Kapasitas: 34.700)Ketua Eberhard FugmannManajer Christian StreichLigaBundesliga2022–2023Bundesliga, ke-5 dari 18Situs webSitus web resmi klub Kostum kandang Kostum tandang Kostum ketiga Musim ini Sport-Club Freiburg atau SC Freiburg merupakan sebuah tim sepak bola Jerman yang bermain di Bundesliga. Didirikan pada tahun 1904 seb…

28°28′N 77°02′E / 28.47°N 77.03°E / 28.47; 77.03 Gurgaon Gurgaon Negara Bagian - Distrik Haryana - Gurgaon Koordinat 28°28′N 77°02′E / 28.47°N 77.03°E / 28.47; 77.03 Luas - Ketinggian  - 220 m Zona waktu IST (UTC+5:30) Populasi (2011) - Kepadatan 1.514.085 -  Kode - Pos - Telepon - Kendaraan   - 122001 ke 122017 -&…

Abraham PaisLahir(1904-08-18)18 Agustus 1904Butte, MontanaMeninggal22 Oktober 2003(2003-10-22) (umur 99)Benteng Belvoir, Fairfax County, VirginiaKebangsaanAmerikaAlmamaterUniversity of CaliforniaDikenal atasSejarah fisikaThe Genius of Science: A Portrait GalleryKarier ilmiahBidangFisika teoretisPembimbing doktoralRobert Oppenheimer Abraham Pais adalah seorang fisikawan teoretis dan sejarawan fisika abad ke-20. Biografi Lahir dari pasangan dokter dan perawat pada 18 Agustus 1904 di Butte, Mo…

Pour les articles homonymes, voir Sioule (homonymie). la Sioule Le méandre de Queuille (Puy-de-Dôme). Cours de la Sioule. Caractéristiques Longueur 163,7 km [1] Bassin 2 458 km2 [2] Bassin collecteur la Loire Débit moyen 25,6 m3/s (Saint-Pourçain-sur-Sioule) [2] Régime pluvio-nival Cours Source émissaire du lac de Servières · Localisation Vernines (63) · Altitude 1 093 m · Coordonnées 45° 39′ 14″ N, 2° 52′ 04″ E Co…

Penahbisan Cluny III oleh Paus Urbanus II.[1] Untuk bahasan lebih luas tentang topik ini, lihat Kekristenan pada Abad Pertengahan. Lihat pula: Kekristenan pada abad ke-9 dan Kekristenan pada abad ke-11 Pada abad ke-10, Kekristenan telah menyebar ke sepanjang sebagian besar Eropa dan Asia. Gereja Inggris didirikan, dengan sekolah-sekolah monasterinya, dan Gereja Latin dan Gereja Ortodoks Timur meneruskan pemisahan mereka, secara mutlak berpuncak dalam Skisma Besar. Teologi pra-skolastik D…

此條目或其章節极大或完全地依赖于某个单一的来源。 (2021年2月1日)请协助補充多方面可靠来源以改善这篇条目。致使用者:请搜索一下条目的标题(来源搜索:奈温 — 网页、新闻、书籍、学术、图像),以检查网络上是否存在该主题的更多可靠来源(判定指引) 本页面有缅文字母,操作系统及浏览器須支持特殊字母与符号才能正確显示为缅文字母,否则可能變成乱码、…

内華達州 美國联邦州State of Nevada 州旗州徽綽號:產銀之州、起戰之州地图中高亮部分为内華達州坐标:35°N-42°N, 114°W-120°W国家 美國建州前內華達领地加入聯邦1864年10月31日(第36个加入联邦)首府卡森城最大城市拉斯维加斯政府 • 州长(英语:List of Governors of {{{Name}}}]]) • 副州长(英语:List of lieutenant governors of {{{Name}}}]])喬·隆巴爾多(R斯塔夫…

这是马来族人名,“尤索夫”是父名,不是姓氏,提及此人时应以其自身的名“法迪拉”为主。 尊敬的拿督斯里哈芝法迪拉·尤索夫Fadillah bin Haji YusofSSAP DGSM PGBK 国会议员 副首相 第14任马来西亚副首相现任就任日期2022年12月3日与阿末扎希同时在任君主最高元首苏丹阿都拉陛下最高元首苏丹依布拉欣·依斯迈陛下首相安华·依布拉欣前任依斯迈沙比里 马来西亚能源转型与公共…

土库曼斯坦总统土库曼斯坦国徽土库曼斯坦总统旗現任谢尔达尔·别尔德穆哈梅多夫自2022年3月19日官邸阿什哈巴德总统府(Oguzkhan Presidential Palace)機關所在地阿什哈巴德任命者直接选举任期7年,可连选连任首任萨帕尔穆拉特·尼亚佐夫设立1991年10月27日 土库曼斯坦土库曼斯坦政府与政治 国家政府 土库曼斯坦宪法 国旗 国徽 国歌 立法機關(英语:National Council of Turkmenistan) 土…

Pour les articles homonymes, voir Martin. Stu MartinThe Trio, Stu Martin, 1971BiographieNaissance 11 juin 1938LibertyDécès 12 juin 1980 (à 42 ans)9e arrondissement de ParisSépulture Cimetière du Père-Lachaise, Grave of Stu Martin (d)Nom de naissance Stewart Victor MartinNationalité américaineActivité Musicien de jazzPériode d'activité à partir de 1979Autres informationsInstrument BatterieGenre artistique JazzTombe au cimetière du Père-Lachaise.modifier - modifier le code - mod…

Township in Burlington County, New Jersey, US Township in New Jersey, United StatesMedford, New JerseyTownshipDowntown Medford at County Road 541 and Union Street, August 2016 SealLocation of Medford in Burlington County highlighted in red (right). Inset map: Location of Burlington County in New Jersey highlighted in red (left).Census Bureau map of Medford Township, New JerseyMedfordLocation in Burlington CountyShow map of Burlington County, New JerseyMedfordLocation in New JerseyShow map of New…

Cotton mill in Greater Manchester, England Royton Ring MillThe mill before 1951Location in Greater ManchesterCottonSpinning (ring & doubling mill)LocationRoyton, Greater Manchester, EnglandFurther ownershipLancashire Cotton Corporation (1935)Courtaulds (1964)Coordinates53°33′17″N 2°07′09″W / 53.5546°N 2.1191°W / 53.5546; -2.1191ConstructionCompleted1908Renovated 1:1912 (expanded) Design teamArchitecture FirmP.S.StottPowerEngine makerUrmson & ThompsonEn…

Kembali kehalaman sebelumnya