Results for “File operations & integrity”
Small, practical examples. Search by task or narrow things down below.
Calculate a file’s SHA-256 digest
PowerShell: Get-FileHash hashes bytes without requiring the caller to load the whole file.
PowerShell✓ Tested
Copy a file to a chosen destination
PowerShell: LiteralPath prevents wildcard characters in the source filename from being interpreted.
PowerShell✓ Tested
Delete only a named scratch file
PowerShell: Use LiteralPath and avoid recursive removal for a single known file.
PowerShell✓ Tested
Distinguish a file from a directory
PowerShell: Test-Path can constrain the kind of item that is accepted.
PowerShell✓ Tested
Find matching files recursively
PowerShell: Select files explicitly and sort their names for predictable presentation.
PowerShell✓ Tested
Move a file into another directory
PowerShell: Move-Item transfers an existing file to the chosen destination directory.
PowerShell✓ Tested
Read a file lazily through the .NET line iterator
PowerShell: ReadLines avoids creating one string containing the entire file.
PowerShell✓ Tested
Read a file size in bytes
PowerShell: The Length property of a file item reports its logical byte size.
PowerShell✓ Tested
Rename a file in its current directory
PowerShell: Rename-Item changes the name without moving the item to another directory.
PowerShell✓ Tested
Append a line while keeping earlier content
PowerShell: Add-Content appends using an explicitly selected encoding.
PowerShell✓ Tested
Archive filenames safely with null delimiters
Linux Commands: Use find -print0 with tar --null to preserve spaces and embedded newlines in filenames.
Linux Commands✓ Tested
Compress a stream to a chosen filename
Linux Commands: Use gzip -c to leave the source file untouched and choose the destination explicitly.
Linux Commands✓ Tested