File

File Operations

CopyTo copies the file to a destination path. MoveTo moves the file to a new location - the original is removed. Delete() removes the current file. Delete(string) removes the file at a specified path. ToGPALObject() returns the GPALFile instance typed as IGPALFile for interface-based use.

These operations work on the file specified by WithFileName (or GPAL.FileFor).

The path itself is readable in pieces: DirectoryPart is the folder and FilePart is the name with its extension, both for the file the GPALFile is currently on, which is what CopyTo and MoveTo need when a destination is built from where the file came from.

SaveTo saves the files as an archive, a zip, gz, tar or tar.gz picked by the destination's extension. See Archives: Opening and Saving.

NOTE

A GPALFile holds however many files its name matched, so the path pieces come in a singular and a plural. DirectoryPart and FilePart answer for the one file the object is on. DirectoryParts and FileParts answer for every file it holds, in the same order as Filenames, so a wildcard that matched thirty files gives thirty of each. A name that matched nothing answers with empty rather than failing, because asking a GPALFile for its folder is not the same as asking it to find something.

Examples

GPAL Fluent: High-level fluent C# API

//CopyTo and MoveTo accept a full destination path including the filename. If the destination directory does not exist, the operation will fail - ensure the target directory exists before calling. Building a destination out of the pieces rather than out of the whole path is what keeps a copy working when the source moves: DirectoryPart changes and FilePart does not.

// Copy a downloaded file to a target directory

GPAL.File

.WithFileName("C:\Downloads\report.pdf")

.ToGPALObject()

.CopyTo("C:\Archive\reports\2026-report.pdf");


// Move a processed file

GPAL.File

.WithFileName("C:\Inbox\data.csv")

.ToGPALObject()

.MoveTo("C:\Processed\data.csv");


// Delete a temporary file

GPAL.File

.WithFileName("C:\temp\working.tmp")

.ToGPALObject()

.Delete();

💬 Ask GPAL