File

File Configuration

A string is a GPALFile. Anywhere GPAL asks for one, hand it a path and it converts on its own. Nothing has to be called and nothing has to be built. GPAL.FileFor(path) builds one to hold and reuse, which is what you want when the same file is read, written and then read back. GPAL.File is the full builder, for when the file needs more said about it than where it is. The one time a cast is needed: a method that takes a string as well as a GPALFile, where the string means something other than a path. Write (GPALFile)path to say which you meant. Nothing else needs it. WithFileName sets the path, and takes a wildcard, so one GPALFile can be many files. WithDelimiter sets the character between fields. WithColumnName and WithColumnNames name the columns for a file with no header row, one list per file when there are several. WithFirstLineIsColumnNames says the first row holds the names, WithIgnoreFirstLineColumnNames skips that row entirely, and WithUseSameColumnNamesForAllFiles gives every file the first list instead of one each. WithColumnsEnclosedInQuotes turns on quoted field parsing. WithOverwriteFile decides what .Next hands back: the same filename every time, so a save replaces what is there, or a fresh unique name beside it. Without it, .Next uniquifies.

NOTE

Some files GPAL has to create because the workflow never named one. The clearest case is a GPALFile built from a url: GPAL downloads it before there is a path to put it, so it lands in the temp directory under the name the url ended with. Temporary browser profiles and other working files go there too. You do not have to set this. Left alone it uses a GPALfilesSafeToDelete folder beside the exe, named that way because everything in it is disposable, and it is created on demand. This is not the browser's download directory, which is a separate setting for files a site actually sends you.

WARNING

WithTempDirectory is a GPAL-level setting, and GPAL settings are written to GPAL.yaml, which loads on every run. Two things write that file: a GPAL version change, and a missing GPAL.yaml. Either one writes whatever the settings hold at that moment, so a path set in one run can be baked into the yaml and apply to every run after it, including runs that never mention it. Point it somewhere permanent that is meant to hold disposable files, never at a folder that belongs to one run, one test or one machine. If a path did get stuck, the fix is to remove the TempDirectory line from GPAL.yaml, which puts the default back.

Examples

GPAL Fluent: High-level fluent C# API

//The first call passes a plain string and gets a GPALFile, which is how most workflows use files. The builder is there for the rest: a delimiter that is not a comma, columns for a file with no header row, quoted fields, a wildcard that makes one GPALFile stand for many. The cast on the last one is not decoration. FillInFrom takes a GPALFile or a string, and the string is the text to type rather than a path, so (GPALFile) is how you say read the file instead. The same goes for AppendFrom, InsertFrom, WithInput, WithImage and LeftClickAndUpload. Everywhere else there is no competing overload and the bare path is enough.

// a path is a GPALFile. this is the whole of it for most workflows

browser

.WithSelector(downloadLink)

.LeftClickAndDownload(@"c:sdi eport.pdf");


// held and reused, so the same file is written and then read back

GPALFile report = GPAL.FileFor(@"c:sdi eport.csv");


// the builder, for a file that needs describing

GPALFile customers = GPAL.File

.WithFileName(@"c:datacustomers.csv")

.WithFirstLineIsColumnNames(true)

.WithColumnsEnclosedInQuotes(true)

.ToGPALObject();


GPALFile exports = GPAL.File

.WithFileName(@"c:dataexport.tsv")

.WithDelimiter(' ')

.WithColumnNames("Id,Name,Email,Status")

.ToGPALObject();


// FillInFrom takes both, and a bare string is the text to type. the cast says read the file instead

browser

.WithSelector(nameField)

.FillInFrom("Michael") // types Michael

.WithSelector(form)

.FillInFrom((GPALFile)@"c:sdivalues.csv"); // fills from the file

💬 Ask GPAL