The filesystem helpers inDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/PrinceOfCookies/CookieOS/llms.txt
Use this file to discover all available pages before exploring further.
cosUtils extend CC:Tweaked’s built-in fs API with recursive file counting, byte-accurate directory sizing, human-readable size formatting, name-based file search, filtered and annotated directory listings, safe file reading, and a slow-print file/directory deletion helper. The startup/replacements.lua startup module additionally patches fs.attributes2 onto the fs table, providing enhanced metadata with formatted sizes and human-readable age timestamps.
cosUtils.fileCount(directory)
Recursively counts every file (not directory) insidedirectory, skipping the rom/ path to avoid counting ROM files.
Path to the directory to scan. Pass
"" or "/" for the root of the computer’s filesystem.number.
cosUtils.loadingBar() calls cosUtils.fileCount("") internally to scale the animation duration, so the boot bar takes longer on more populated computers.cosUtils.getDirectorySize(sPath)
Recursively walkssPath and sums the byte sizes of every file it contains. Directories themselves have no size contribution; only leaf files are counted via fs.getSize().
Path to the directory to measure.
number (total bytes).
cosUtils.formatSize(size)
Converts a raw byte count into a concise, human-readable string. The output format depends on magnitude:| Range | Format | Example |
|---|---|---|
| ≥ 1 MiB (1,048,576 B) | "X.XX MB" | "1.00 MB" |
| ≥ 1 KiB (1,024 B) | "X.XX KB" | "1.50 KB" |
| < 1 KiB | "X B" | "42 B" |
Byte count to format. Coerced with
tonumber() before processing.string.
cosUtils.getFilesAndDirs(sDir)
Lists the contents ofsDir and separates them into two tables: one for files and one for subdirectories. Each entry is a formatted string that includes the item name and its size (via cosUtils.formatSize()). Read-only items are prefixed and suffixed with the middle-dot character · (\xB7).
Hidden items (names starting with .) are omitted unless the list.show_hidden CC:Tweaked setting is true.
The directory path to list.
tFiles, tDirs — two tables of formatted strings.
cosUtils.findFile(filename, directory)
Recursively searches for a file whose name exactly matchesfilename, starting from directory. The search descends into every subdirectory it finds.
The exact filename to search for (not a pattern).
The root directory to start the search from. Defaults to
"/".string if the file is found, or nil if it is not.
cosUtils.readFile(path)
Opens a file in read mode, reads all of its contents, closes the handle, and returns the content string. On failure (e.g. the file does not exist), returnsnil and an error message.
Absolute or shell-relative path to the file.
content (string), nil on success, or nil, errorMessage (string) on failure.
cosUtils.del(name, dir)
Deletes a file or directory with atextutils.slowPrint status message. The delay before deletion is proportional to the item’s size (size in bytes divided by 1000 seconds), simulating a visible deletion process. Before deleting, the function ensures that os/.install is not accidentally removed — if the file is missing from the root, it is moved there first.
Name (or path) of the file or directory to delete.
Pass
true if name refers to a directory. Pass false (or nil) for a file.fs.attributes2(path, hdOnly)
fs.attributes2 is patched onto the built-in fs table by startup/replacements.lua at boot. It calls the standard fs.attributes() and then appends three extra fields: a formatted size string, and human-readable modified and created timestamps showing elapsed time (e.g. "2 days, 3 hrs") rather than raw epoch values.
If path does not exist as an absolute path, the function automatically resolves it relative to shell.dir().
Path to the file or directory.
If
true, timestamps use a condensed two-component format (e.g. "2 days, 3 hrs" or "15 mins, 30 secs"). If false, all non-zero time components from years down to seconds are included.fs.attributes() table with three additional fields:
| Field | Type | Example |
|---|---|---|
size | string | "4.50 KB" |
modified | string | "2 days, 3 hrs" |
created | string | "5 weeks, 2 days" |
readonly | boolean | false |
For directories,
size reflects the recursive total from getDirectorySize(), and modified reflects the most recently modified file inside the directory rather than the directory entry itself.