Wolfram: List Files (Walk Directory)
Get Dir Content (List File Names)
summary
FileNames[]
→ all files in the current directory.FileNames[sPattern]
→ lists all files in the current directory whose names match the string pattern sPattern.FileNames[sPatternList]
→ lists all files whose names match any of the patterns.FileNames[All,dir]
→ lists all files in the directory dir.FileNames[sPatternList,dirList]
→ lists files with names matching any given pattern in any given dirs.FileNames[sPatternList,dirs,n]
→ includes files that are in subdirectories up to n levels down.
-
FileNames[strPattern, dir, depth]
-
return a List of all files and directories in directory dir up to depth.
- The pattern strPattern can be a wildcard pattern or Wolfram: Regular Expression or Wolfram: String Expression
- strPattern must match the file fullpath completely, not just containing the pattern.
- strPattern can be a list of patterns.
- strPattern can be
All
, means all files.
- dir can be a fullpath or relative path, or
"."
for current dir. - dir can be a list of dirs.
- depth is a integer or
Infinity
. It means depth of dir.
(* list all files in a dir, all subdirs *) FileNames[All, "c:/Users/xah/web/xahlee_info/M", Infinity] (* {c:/Users/xah/web/xahlee_info/M\detect_zero_vector.html, c:/Users/xah/web/xahlee_info/M\Elementary_Intro_to_Wolfram_Language_Review.html, c:/Users/xah/web/xahlee_info/M\history_of_notebook.html, c:/Users/xah/web/xahlee_info/M\i, c:/Users/xah/web/xahlee_info/M\ic, c:/Users/xah/web/xahlee_info/M\ic\plane_curve_2024-03-01_132521.png, c:/Users/xah/web/xahlee_info/M\ic\plane_curve_2024-03-01_132538.png } *)
Current Directory (Only File Names vs Full Path vs Relative Path)
(* if no dir is given, use current dir. and return values are just file names. *) FileNames["*.txt"] (* {xah-find-2025-07-09_075353_5fa.txt, xah-find-2025-07-09_094715_516.txt, xah-find-2025-07-10_085007_5f0.txt, xnew.txt, xx_2025-04-13_104411_eac55.txt, xx_2025-05-27_151301_77fc2.txt, xx_2025-07-08_192442_81428.txt} *) (* HHHH------------------------------ *) (* if dir is given, and is full path, return values are full path. *) FileNames["*.txt", "c:/Users/xah/.emacs.d/temp"] (* {c:/Users/xah/.emacs.d/temp\xah-find-2025-07-09_075353_5fa.txt, c:/Users/xah/.emacs.d/temp\xah-find-2025-07-09_094715_516.txt, c:/Users/xah/.emacs.d/temp\xah-find-2025-07-10_085007_5f0.txt, c:/Users/xah/.emacs.d/temp\xnew.txt, c:/Users/xah/.emacs.d/temp\xx_2025-04-13_104411_eac55.txt, c:/Users/xah/.emacs.d/temp\xx_2025-05-27_151301_77fc2.txt, c:/Users/xah/.emacs.d/temp\xx_2025-07-08_192442_81428.txt} *) (* HHHH------------------------------ *) (* if dir is given, and is relative path, return values are relative path. *) FileNames["*.txt", "../temp"] (* {../temp\xah-find-2025-07-09_075353_5fa.txt, ../temp\xah-find-2025-07-09_094715_516.txt, ../temp\xah-find-2025-07-10_085007_5f0.txt, ../temp\xnew.txt, ../temp\xx_2025-04-13_104411_eac55.txt, ../temp\xx_2025-05-27_151301_77fc2.txt, ../temp\xx_2025-07-08_192442_81428.txt} *)
List Files of Dir and Subdirs (recurse)
List all files, including any subdirectories to infinite depth:
FileNames[ All, "c:/Users/xah/Downloads/" , Infinity]
up to depth 2:
FileNames[ All, "c:/Users/xah/Downloads/" , 2]
List Files, Filter by File Extension
FileNames["*.html","c:/Users/xah/web/"]
FileNames[ {"*.html", "*.css"}, "c:/Users/xah/"]
List Files of Multiple Directories
list all file names ending in .html or .css, in several directories:
FileNames[ {"*.html", "*.css"}, {"c:/Users/xah/Documents/", "c:/Users/xah/Downloads/"}]
Map Function to Files
Wolfram. Shell Scripting Tasks
- Wolfram: Shell Scripting Tasks
- Wolfram: Navigate Directory
- Wolfram: List Files (Walk Directory)
- Wolfram: File Path Functions
- Wolfram: Delete Dir
- Wolfram: is File or Dir
- Wolfram: File Exist
- Wolfram: Get File Date
- Wolfram: Get File Size
- Wolfram: Print File Content
- Wolfram: Get File Hash
- Wolfram: Read File
- Wolfram: Read File from Web
- Wolfram: Write File
- Wolfram: Load a Package or File
- Wolfram: Get Environment Variable
- Wolfram: Date Time
- Wolfram: Find Replace Text 📜