WolframLang: List Files (Walk Directory)

By Xah Lee. Date: . Last updated: .

List File Names

return a List of all files (and directories) in the current directory. Each item is a path.


list files of current dir whose name match a string pattern.

The pattern can be a wildcard pattern or regex

e.g. FileNames["*.html"] for all html files.

FileNames[{strPattern1, strPattern2 etc}]
match any of the patterns.
FileNames[ALL, dir]
all files in a given dir.
FileNames[strPatterns, dir]
any of the patterns.
FileNames[strPatterns, dirList]
any of the patterns from any of the given dir.
FileNames[strPatterns, dir, n]
to depth n.

(the filepath can be relative. [see Navigate Directory])

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

list all file names ending in .html:


filter by multiple extensions:

{"*.html", "*.css"},

List Files of Multiple Directories

list all file names ending in .html or .css, in several directories:

{"*.html", "*.css"},

WolframLang: Shell Tasks