Skip to main content
Version: 1.0.0

opendir/readdir

List files in a directory

interface AdbSyncEntry extends AdbSyncStat {
mode: number;
size: bigint;
mtime: bigint;
get type(): LinuxFileType;
get permission(): number;

uid?: number;
gid?: number;
atime?: bigint;
ctime?: bigint;

name: string;
}

declare class AdbSync {
opendir(path: string): AsyncGenerator<AdbSyncEntry, void, void>;
readdir(path: string): Promise<AdbSyncEntry[]>;
}
Android 10 and belowAndroid 11 and above
Adb feature nameNonels_v2
Sync commandLISTLST2
Size larger than 4GBNoYes
Returns uid, gid, atime and ctimeNoYes

opendir returns an async generator that yields file entries in the directory. readdir collects all entries and returns an array.

For a large directory with hundreds of files, readdir may take tens of seconds to finish. opendir can provide a better user experience by yielding entries as they are received.

Example

Use opendir

for await (const entry of sync.opendir('/sdcard')) {
console.log(entry.name);
}
READ ALL STREAMS!

ADB is a multiplexing protocol (multiple logic streams are transferred over one connection), so blocking one stream will block all other streams.

You must continuously read from all sync connections to prevent this from happening.

For example, you can't create another sync connection or call other methods on Adb when opendir is still running. Upcoming data for opendir will block other operations.

Use readdir

const entries = await sync.readdir("/sdcard");
for (const entry of entries) {
console.log(entry.name);
}