Results for “standard”
Small, practical examples. Search by task or narrow things down below.
Copy a file and preserve its metadata
Python: Use copy2 for a file copy that also attempts to preserve timestamps and permission bits.
Python✓ Tested
Copy a file to a folder
Create a backup folder if needed, then copy a file into it while preserving its modification time and permission bits.
file✓ Tested
Copy a file without overwriting
C#: File.Copy defaults to refusing a destination that already exists.
C#✓ Tested
Copy a file without replacing an existing destination
Java: Files.copy fails if the destination already exists unless replacement is explicitly enabled.
Java✓ Tested
Copy a slice without sharing storage
Copy a slice without sharing storage using a complete Go program with explicit sample inputs.
Go✓ Tested
Copy a stream and count its bytes
Copy a stream and count its bytes using a complete Go program with explicit sample inputs.
Go✓ Tested
Copy entries into another map
Copy entries into another map using a complete Go program with explicit sample inputs.
Go✓ Tested
Copy nested mutable data independently
Python: Use deepcopy when changes to nested lists must not affect the original object.
Python✓ Tested
Copy text into a fixed buffer
Use snprintf and check for truncation when copying a C string.
C✓ Tested
Count days between calendar dates
Python: Subtract date objects to get an exact calendar-day difference.
Python✓ Tested
Count days between two dates
Java: Use ChronoUnit.DAYS for an elapsed count rather than a Period day component.
Java✓ Tested
Count lines in a file
Count newline characters in a text file, printing only the count without the filename.
lines✓ Tested