stat()


This method allows you to get information about a file or directory.

Syntax

puter.fs.stat(path)

Parameters

path (string) (required)

The path to the file or directory to get information about. If path is not absolute, it will be resolved relative to the app's root directory.

Return value

Returns a promise that resolves to the file or directory object of the specified file or directory.

Examples

Get information about a file

Run

<html>
<body>
    <script src="https://js.puter.com/v2/"></script>
    <script>
        (async () => {
            // () create a file
            await puter.fs.write('hello.txt', 'Hello, world!');
            puter.print('hello.txt created<br>');

            // (2) get information about hello.txt
            const file = await puter.fs.stat('hello.txt');
            puter.print(`hello.txt name: ${file.name}<br>`);
            puter.print(`hello.txt path: ${file.path}<br>`);
            puter.print(`hello.txt size: ${file.size}<br>`);
            puter.print(`hello.txt created: ${file.created}<br>`);
        })()
    </script>
</body>
</html>