Results for “File operations & archives”
Small, practical examples. Search by task or narrow things down below.
Read a filename stem and extension
C#: Use Path helpers instead of splitting a path on dots or directory separators.
C#✓ Tested
Read the byte size of a regular file
C++: file_size reads filesystem metadata without loading file contents.
C++✓ Tested
Rename a file in its current directory
PowerShell: Rename-Item changes the name without moving the item to another directory.
PowerShell✓ Tested
Rename a known file through filesystem
C++: filesystem::rename reports an error by exception when the operation fails.
C++✓ Tested
Visit files recursively
Java: Close the stream returned by Files.walk and sort relative paths for stable output.
Java✓ Tested
Append a line while keeping earlier content
PowerShell: Add-Content appends using an explicitly selected encoding.
PowerShell✓ Tested
Calculate a lexical relative path
C++: lexically_relative compares path components without requiring the paths to exist.
C++✓ Tested
Load a small properties configuration
Java: Use a Reader to make the configuration character encoding explicit.
Java✓ Tested
Normalize relative path components
Java: Path.normalize removes redundant dot components without accessing the filesystem.
Java✓ Tested
Replace a path extension
C#: Path.ChangeExtension transforms a path string without moving or creating a file.
C#✓ Tested
Set owner-only read and write permissions
C++: Replace ordinary permission bits with the requested owner permissions.
C++✓ Tested
Write and read binary bytes
Java: Use the byte-oriented Files methods when text encoding should not be involved.
Java✓ Tested