WolframLang: List Files (Walk Directory)

By Xah Lee. Date: . Last updated: .

Get Dir Content (List File Names)

FileNames[]

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

FileNames

FileNames[]
FileNames[strPattern]

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

The pattern can be a wildcard pattern or regex

Example: 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.)

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:

FileNames["*.html","c:/Users/xah/web/"]

filter by multiple extensions:

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

FileSystemMap

WolframLang, Shell Tasks