WolframLang: List Files (Walk Directory)

By Xah Lee. Date: . Last updated: .

List all files in current directory. Result is a list of paths: {path1, path2 etc}

List Files

FileNames[]
return a list of all files (and directories) in the current directory.
FileNames
FileNames[]
FileNames[strPattern]
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:

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/"}]

WolframLang: Shell Tasks

WolframLang in Depth

Basics

Comment, Print

String

Arithmetic

List

Expression, Atom, Head

Boolean

Conditional

Variable

Loop

Data Structure

Function

Pattern Matching

Advanced

Shell Tasks

Misc