A Brief Overview of the File and Directory Entries API

Process automation to efficiently manage files and documentation storage.System online documentation database and document management.Archiving documents in folders for efficient management secure.

The File and Directory Entries API is a web platform feature that lets web apps process directories and file lists that a user provides, typically through drag-and-drop or file/directory picker inputs. Think of it as a practical step beyond the basic File API: instead of dealing with one file at a time, you can work with hierarchies—folders containing files and subfolders—so you can build experiences like “drop a project folder here” or “select a directory to import.”

What it’s for (and what it isn’t)

This API was originally part of a broader effort to support a virtual file system in the browser. Today, its scope is much narrower: it only supports read operations on user-provided data. In other words:

How you get access to entries

Two common entry points:

    • HTMLInputElement.webkitEntries can expose selected entries in certain scenarios.
    • If HTMLInputElement.webkitdirectory is true, the <input> becomes a directory picker, returning directory entries for the chosen folders.

Core concepts and interfaces

At the heart of the API is the idea of an entry—something that can be either a file or a directory:

There are also related extensions exposed elsewhere in the platform, including:

When it shines

You’ll typically reach for this API when you want to:

				
					<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>File and Directory Entries API Demo</title>
    <link href="style.css" rel="stylesheet" />
    <script src="fileandDirectoryEntries_API.js" defer></script>
</head>
    
<body>
    <h1>File & Directory Entries API</h1>
    <p>Drag a folder (with sub-folders) into the box below to see recursion in action.</p>
    
    <!-- 1. The Drop Target -->
    <div id="drop-zone">Drop Files or Folders Here</div>
    
    <!-- 2. The Output Log -->
    <div id="output">Waiting for input...</div>
</body>

</html>
				
			
				
					body {
    font-family: 'Segoe UI', sans-serif;
    padding: 2rem;
    max-width: 800px;
    margin: 0 auto;
}

/* Visual styling for the drop target */
#drop-zone {
    border: 3px dashed #ccc;
    border-radius: 10px;
    padding: 3rem;
    text-align: center;
    color: #666;
    transition: all 0.3s ease;
    background-color: #fafafa;
}

/* Highlight state when dragging over */
#drop-zone.hover {
    border-color: #007bff;
    background-color: #e9f5ff;
    color: #007bff;
}

/* Container for the output log */
#output {
    margin-top: 2rem;
    background: #f4f4f4;
    padding: 1rem;
    border-radius: 5px;
    font-family: monospace;
    white-space: pre-wrap;
    min-height: 100px;
}
				
			
				
					const dropZone = document.querySelector('#drop-zone');
const output = document.querySelector('#output');

// 1. DEFINE FUNCTIONS FIRST (to avoid ReferenceError)
const preventDefaults = (e) => {
	e.preventDefault();
	e.stopPropagation();
};

const log = (text) => {
	output.textContent += text + '\n';
};

/**
 * RECURSIVE FUNCTION
 * This creates a tree structure by checking if an item is a File or Directory.
 */
const traverseFileTree = (item, path = '') => {
	// The path parameter helps us keep track of the current directory structure as we traverse.
	path = path || '';

	if (item.isFile) {
		// CASE 1: It is a specific File
		item.file((file) => {
			log(`📄 FILE: ${path}${item.name} (${file.size} bytes)`);
		});
	} else if (item.isDirectory) {
		// CASE 2: It is a Directory
		log(`📁 FOLDER: ${path}${item.name}`);

		// Create a DirectoryReader to read entries inside this folder
		const dirReader = item.createReader();

		// readEntries returns an array of entries
		dirReader.readEntries((entries) => {
			for (let i = 0; i < entries.length; i++) {
				// RECURSION: Call this function again for the child entry
				traverseFileTree(entries[i], path + item.name + '/');
			}
		});
	}
};

const handleDrop = (e) => {
	// Processing visual cue
	output.textContent = 'Processing...\n';

	// Access the DataTransferItemList interface
	const items = e.dataTransfer.items;

	for (let i = 0; i < items.length; i++) {
		// KEY API METHOD: webkitGetAsEntry()
		const entry = items[i].webkitGetAsEntry();

		if (entry) {
			traverseFileTree(entry);
		}
	}
};

// 2. ATTACH EVENT LISTENERS (After functions are defined)

// Prevent default behaviors
['dragenter', 'dragover', 'dragleave', 'drop'].forEach((eventName) => {
	dropZone.addEventListener(eventName, preventDefaults, false);
});

// Visual cues (Hover effects)
['dragenter', 'dragover'].forEach(() => dropZone.classList.add('hover'));
['dragleave', 'drop'].forEach(() => dropZone.classList.remove('hover'));

// Handle the actual file drop (This was missing in your snippet)
dropZone.addEventListener('drop', handleDrop, false);

				
			

Final takeaway

The File and Directory Entries API fills an important niche: it enables structured imports of user-selected files and directories in a way that the basic File API doesn’t. While it doesn’t offer full filesystem access, it’s a strong fit for modern web apps that need to ingest folder-based data—safely, explicitly, and within the boundaries of what the user has shared.

 
more posts:
Online video streaming platform and digital content management concept with media player interface, cloud library, and multimedia files on laptop, representing content distribution, video marketing
Code

Breaking into the Pipeline: Real-Time Frame Manipulation with the Insertable Streams for MediaStreamTrack API

The experimental Insertable Streams for MediaStreamTrack API closes a long-standing gap in web multimedia by treating live camera feeds as standard Web Streams. By piping individual VideoFrame objects through a TransformStream and recording the transformed output via MediaRecorder, developers can execute frame-by-frame processing—like real-time filtering, watermarking, and computer vision overlays—without relying on hidden canvas hacks.

Discover More »
Apps & Custom Software

What Building Our Own App Taught Us About Building Yours

When Hess WebTech built and launched Tericipe—an Android app that turns printed recipes into a searchable digital collection—in under three months, we had to live with every decision we usually advise clients on. From testing against real-world messy data and handling AI uncertainty to server-side payment security and post-launch maintenance, here are five crucial lessons from our own build that apply to almost any software project.

Discover More »