The most comprehensive cross-platform file operations library for Nim
Originally developed for the Ryton programming language
- π₯ 100+ file operations in one library
- π Cross-platform (Windows/Linux/BSD/macOS)
- β‘ High performance optimized algorithms
- π‘οΈ Type-safe with comprehensive error handling
- π Advanced features: monitoring, filtering, batch ops, extended attributes
- π File & Directory Operations - Create, copy, move, delete files and directories
- π Symbolic & Hard Links - Full support for link creation and management
- π Advanced Search - Find files by name, size, date, and custom filters
- π File System Information - Get disk usage, mount points, and file statistics
- π Permissions & Security - Manage file permissions and secure deletion
- π― Cross-Platform - Works on Windows, Linux, and macOS
- π File Monitoring - Watch directories for changes (basic implementation)
- ποΈ Archive Support - Basic archive creation and extraction
- π Network File Systems - Mount/unmount NFS, SMB shares
Add Files.nim to your project using Nimble:
nimble install https://github.com/CodeLibraty/rytonfiles
Or add to your .nimble
file:
requires "rytonfiles >= 1.0.0"
from file src/Files.nim:
type
FileType* = enum
ftFile,
ftDirectory,
ftSymlink,
ftHardlink,
ftDevice,
ftPipe,
ftSocket,
ftUnknown
FilePermission* = enum
fpRead,
fpWrite,
fpExecute
FilePermissions* = set[FilePermission]
FileInfo* = object
path*: string
name*: string
size*: int64
fileType*: FileType
permissions*: FilePermissions
createdAt*: DateTime
modifiedAt*: DateTime
accessedAt*: DateTime
owner*: string
group*: string
isHidden*: bool
MountPoint* = object
device*: string
mountPath*: string
fileSystem*: string
options*: seq[string]
totalSpace*: int64
freeSpace*: int64
usedSpace*: int64
FilesError* = object of CatchableError
# example
import rytonfiles
let testDir = "test_files"
# Filter
var filter = newFileFilter()
filter.extensions = @[".nim", ".ry"]
filter.minSize = 1024
let files = findFilesWithFilter("/home/rejzi/Picturies", filter)
echo files
# Statistic
let stats = getDirectoryStats("/home/rejzi/Downloads")
echo "Files: ", stats.totalFiles
echo "Size: ", formatFileSize(stats.totalSize)
if not exists(testDir):
createDirectory(testDir)
echo fmt"Created directory: {testDir}"
let testFile = joinPath(testDir, "test.txt")
createFile(testFile, "Hello, RytonFiles library!")
echo fmt"Created file: {testFile}"
printFileInfo(testFile)
echo "\nDirectory tree:"
printDirectoryTree(testDir)
# Clean
removeDirectory(testDir, recursive = true)
echo fmt"Cleaned up: {testDir}"
# Create and write to file
createFile("example.txt", "Hello, World!")
appendTextFile("example.txt", "\nSecond line")
# Copy and move files
copyFile("example.txt", "backup.txt")
moveFile("backup.txt", "archive/backup.txt")
# Batch operations
let copied = batchCopy(@["file1.txt", "file2.txt"], "destination/")
# Create nested directories
createDirectory("path/to/nested/dir", recursive = true)
# Get directory statistics
let stats = getDirectoryStats("my_folder")
echo "Total files: ", stats.totalFiles
echo "Total size: ", formatFileSize(stats.totalSize)
# Clean old files
cleanDirectory("temp/", olderThan = initDuration(days = 7))
# Create a custom filter
var filter = newFileFilter()
filter.extensions = @[".nim", ".ry"]
filter.minSize = 1024
filter.dateFrom = now() - initDuration(days = 30)
let recentNimFiles = findFilesWithFilter("src/", filter)
# Get mount points (Unix/Linux)
when not defined(windows):
let mounts = getMountPoints()
for mount in mounts:
echo mount.device, " -> ", mount.mountPath
# File system info
let fsInfo = getFileSystemInfo(".")
echo "Free space: ", formatFileSize(fsInfo.freeSpace)
# Create and read symbolic links
createSymlink("target_file.txt", "link_to_file.txt")
let target = readSymlink("link_to_file.txt")
echo "Link points to: ", target
- Extended file attributes
- File ownership management
- NFS/SMB mounting
- inotify-based file watching
- Alternate Data Streams
- Network drive mapping
- NTFS-specific features
- All Unix features
- macOS-specific directory locations
The library uses FilesError
for file system related errors:
try:
removeFile("nonexistent.txt")
except FilesError as e:
echo "Error: ", e.msg
- Use
recursive = false
for better performance when you don't need deep directory traversal - Batch operations are more efficient than individual file operations
- File streams provide better performance for large file operations
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
RytonFiles is developed by CodeLibraty Foundation, the creators of the RytonLang programming language.
π Explore our ecosystem:
- RytonLang Compiler - Modern programming language
- RytonFiles - This library
- More tools coming soon...
MIT License - see LICENSE file.
Made with β€οΈ4Nim by Rejzi-dich