Reads the contents of a directory, returning an array of items (files and directories) within it. This method is useful for listing all items in a specified directory in the Puter cloud storage.


Code copied


path (string) The path to the directory to read. If path is not absolute, it will be resolved relative to the app's root directory.

Return value

A Promise that resolves to an array of fsitems (files and directories) within the specified directory.


Read a directory

Code copied
    <script src="https://js.puter.com/v2/"></script>
        puter.fs.readdir('./').then((items) => {
            // print the path of each item in the directory
            puter.print(`Items in the directory:<br>${items.map((item) => item.path)}<br>`);
        }).catch((error) => {
            puter.print(`Error reading directory: ${error}`);