fs file system library
fs file system library
Function
fs(path) creates a file system path object, providing read and write, copy, move, delete, directory traversal and path information reading capabilities around the path.
API List
| API | Description |
|---|---|
| fs.path | Returns the path text bound to the current fs object. |
| fs.to_string | Returns the path text bound to the current fs object. |
| fs.read | Read the contents of the text file. |
| fs.real_path | Returns the real absolute path after the operating system resolves the symbolic link and ... |
| fs.binary | Read the binary content of the file. |
| fs.lines | Read text files line by line. |
| fs.write | Overwrite the content of the written file. |
| fs.atomic_write | Atomic replacement of content via temporary files in the same directory, rejecting conflicts as per old SHA-256. |
| fs.append | Append content to the end of the file. |
| fs.prepend | Write content to the beginning of the file. |
| fs.size | Read file or directory metadata size. |
| fs.rename | Rename the current path to the target path. |
| fs.move | Move the current file or directory to the target directory, and the file name remains unchanged. |
| fs.copy | Copy files or directories to the target path. |
| fs.delete | Delete a file or directory. |
| fs.create_dir | Create a directory recursively. |
| fs.create_file | Creates a file and writes optional initial content. |
| fs.list | List directory entries. |
| fs.is_dir | Determine whether the path is a directory. |
| fs.is_file | Determine whether the path is an ordinary file. |
| fs.is_relative | Determine whether the current path is a relative path. |
| fs.is_absolute | Determine whether the current path is an absolute path. |
| fs.is_symlink | Determine whether the path is a symbolic link. |
| fs.is_exists | Determine whether the path exists. |
| fs.basename | Returns the last level name of the path. |
| fs.filename | Returns the last-level name of the path minus the extension. |
| fs.extension | Returns the path extension. |
Examples
file = fs('demo.txt') file.write('BT') result = file.read() // Output: BT print result
Notes
- The path parameter of fs() will be parsed by the VM according to the current source code directory and project root rules.