FIND YOUR NEXT FEW LINES

Results for “write file”

Small, practical examples. Search by task or narrow things down below.

880 snippets foundClear filters
PythonFile operations & archives

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
Docker / ComposeExecution & file transfer

Copy a file into a created container

Docker / Compose: docker cp can copy into a container before its process starts.

Docker / Compose✓ Tested
Docker / ComposeBuild images

Copy a file into an image

Include a small application file during the build.

Dockerfile✓ Tested
PowerShellFile operations & integrity

Copy a file to a chosen destination

PowerShell: LiteralPath prevents wildcard characters in the source filename from being interpreted.

PowerShell✓ Tested
Linux CommandsFiles & folders

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
Linux CommandsDates & process utilities

Copy a file with explicit permissions

Linux Commands: Use install to create parent directories and set the destination mode in one operation.

Linux Commands✓ Tested
C#File operations & paths

Copy a file without overwriting

C#: File.Copy defaults to refusing a destination that already exists.

C#✓ Tested
JavaFile operations & binary data

Copy a file without replacing an existing destination

Java: Files.copy fails if the destination already exists unless replacement is explicitly enabled.

Java✓ Tested
Linux CommandsStreams & byte tools

Count bytes in a file

Linux Commands: Use wc -c for byte length rather than Unicode character count.

Linux Commands✓ Tested
Linux CommandsText processing

Count lines in a file

Count newline characters in a text file, printing only the count without the filename.

lines✓ Tested
C#File operations & paths

Create a file only when it does not exist

C#: FileMode.CreateNew prevents accidental replacement of existing content.

C#✓ Tested
PythonFile operations & archives

Create a file without overwriting an existing one

Python: Use exclusive creation mode and handle FileExistsError explicitly.

Python✓ Tested