Directories, Paths, and FileSystemEntity
Navigate and inspect the file system.
Directories, Paths, and FileSystemEntity is a free Dart Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Dart Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
The Directory Class
Just as File names a file, the Directory class names a folder. You build one from a path string, ready to inspect or create.
final dir = Directory('logs');Create a Folder
Call create to make the folder. Add recursive: true and Dart builds every missing parent folder for you in one go.
await dir.create(recursive: true);Where Am I Running
Need the folder your program started in? Directory.current gives the working directory, the anchor for relative paths.
print(Directory.current.path);List Folder Contents
Use list to stream what is inside a folder. Each event is an entity you can examine one at a time.
await for (final e in dir.list()) print(e.path);Go Deep With recursive
Pass recursive: true to list to walk every subfolder too, visiting the whole tree under your directory.
dir.list(recursive: true);FileSystemEntity, the Parent
Files and directories both extend FileSystemEntity. That shared base is why list can hand you either kind in one stream.
What Kind Is It
To tell a file from a folder, use FileSystemEntity.isDirectory or check the entity type. This keeps your loops branch-safe.
if (await FileSystemEntity.isDirectory(e.path)) {}Join Paths Safely
Do not glue paths with plain strings. The path package joins parts using the right separator for each platform.
import 'package:path/path.dart' as p;Build a Path
Call p.join with each segment and you get a clean, correct path on Windows, macOS, or Linux alike.
final full = p.join('data', 'users', 'a.txt');Split a Path Apart
Pull a path into pieces with helpers like p.basename for the file name and p.dirname for its folder.
print(p.basename('/data/a.txt'));Get the Extension
Need just the suffix? p.extension returns it with the dot, so you can filter files by type with ease.
print(p.extension('photo.png'));Quick Check
You need a cross-platform path from several segments. What is the safe way?
Recap
You can create folders, list their contents recursively, tell files from dirs, and build paths safely with the path package.
Frequently asked questions
Is the “Directories, Paths, and FileSystemEntity” lesson free?
Yes — the full text of “Directories, Paths, and FileSystemEntity” is free to read here on the web, and the Dart Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Dart Academy course, upgrade to CoddyKit PRO.
What will I learn in “Directories, Paths, and FileSystemEntity”?
Navigate and inspect the file system. You practise Dart Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Dart Academy?
No prior experience is required. Dart Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Directories, Paths, and FileSystemEntity” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Dart Academy lesson?
Yes. Every Dart Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Reading and Writing Files
- Directories, Paths, and FileSystemEntity
- Streaming Large Files
- Stdin, Stdout, and Process Args