Results for “Files & paths”
Small, practical examples. Search by task or narrow things down below.
Read a file line by line
Read C++ text lines without loading the whole file at once.
C++✓ Tested
Read a filename extension
Extract the final extension from a C++ filesystem path.
C++✓ Tested
Read a text file
Open a UTF-8 text file and read its contents. A context manager closes the file automatically, even if reading fails.
file✓ Tested
Read a text file
Load a small text file into a C# string.
C#✓ Tested
Read a UTF-8 file
Read a small UTF-8 file into a Java string.
Java✓ Tested
Read a whole text file
Load text as one string instead of one item per line.
Get-Content✓ Tested
Remove only a named untracked scratch file
Git: Use a narrow pathspec after reviewing the dry run; clean cannot recover untracked content.
Git✓ Tested
Run an image as a non-root user
Choose an unprivileged numeric identity for the default process.
Dockerfile✓ Tested
Show the current directory
Print the absolute path of your current working directory before running commands that depend on relative paths.
directory✓ Tested
Stash edits to one chosen file
Git: A pathspec limits the stash to selected paths while other changes remain in the working tree.
Git✓ Tested
Write a text file
Save a string to a UTF-8 text file and close the file automatically when the write finishes.
file✓ Tested
Write a text file
Write a C# string to a UTF-8 file.
C#✓ Tested