Skip to content

A 4D component with some basic file and folder utility methods

License

Notifications You must be signed in to change notification settings

dbeaubien/FileFolder_Utils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FileFolder_Utils

A modern component that provides basic file and folder utility methods.

Features

  • Provides basic functionality for working with files and folders
  • Provides a set of methods to load files through a file buffer that adds additional abilities for retrieving the file contents from disk.

Requirements

  • 4D v18 is required.

Installation and Use

Copy the FileFolder_Utils.4dbase into the Components folder of your application. It is suggested that you compile the component before installing it into your own projects.

Examples

Example #1 - tbd

code here

Example #2 - tbd

code here

File / Folder Shared Methods

The methods provide a some basic functionality for working with files and folders.

File_DoesExist (pathToFile:c_text) returns doesExist:c_boolean

Returns true if the file exists. Any missing parent folders will be created if missing.

File_IsCSV (pathToFile:c_text) returns isCSV:c_boolean

Returns true if the file is a CSV. Recognizes a 1st line of of the csv file is a "sep=" line.

TESTS performed:

  • Is file extension ".csv" or ".txt"
  • Look at first line, expect line of comma separated values.
  • At least 2 non-empty values in the header line.

File_IsJPG (pathToFile:c_text) returns isJPG:c_boolean

Returns true if the image file is a JPG. The file extension is ignored, it looks at the image directly.

File_IsPNG (pathToFile:c_text) returns isPNG:c_boolean

Returns true if the image file is a PNG. The file extension is ignored, it looks at the image directly.

File_IsTabDelimited (pathToFile:c_text) returns isTabDelimited:c_boolean

Returns true if the file is tab-delimited.

TESTS performed:

  • Is file extension ".tsv" or ".txt"
  • Look at first line, expect line of tab-delimited values.
  • At least 2 non-empty values in the header line.

Folder_DoesExist (pathToFolder:c_text) returns doesExist:c_boolean

Returns true if the file exists.

Folder_ParentName (folderPath:c_text) returns parentFolderPath:c_text

Returns the parent folder of the folderPath passed in.

Folder_VerifyExistance (pathToFolder:c_text)

Creates a folder if it does not exist. If necessary, it will recursively create the parent folders as well.

FileBuffer Shared Methods

FileBuffer_Init (docRef:c_time {; bufferSize:c_longint})

Initializes the necessary vars and pre-fills the buffer from the already opened file.

FileBuffer_TellMeTheEOL () returns theEol:C_text

Scans the filebuffer to figure out what the EOL is.

FileBuffer_EOF () returns isEOF:C_boolean

Returns true if we are at the end of file.

FileBuffer_GetFilePostion () returns currentPositionInFile:c_longint

Returns a logical position in the file.

FileBuffer_FetchData_BySize (numBytesToFetch:c_longint) returns fileContent:c_text

This method returns the specified number of bytes. If it cannot then that means that the file is empty.

FileBuffer_FetchData_ByString (matchOnText:c_text{; matchOnText2:c_text}) returns fileContent:c_text

Returns text from the buffer up to AND INCLUDING the matchOnText or matchOnText2 values.

NOTE: This differs from RECEIVE PACKET.

FileBuffer_FetchData_PeekAhead (numCharactersToReturn:c_longint) returns fileContent:c_text

Returns fileContent up to the number of characters specified without advancing the current position in the file.

FileBuffer_FetchCSVLine (eol:C_text , valuesArrPtr:C_pointer)

Populates the array with the parsed values from the line. Recognizes a 1st line of "sep=" line.

FileBuffer_FetchTabDelimitedLne (eol:C_text , valuesArrPtr:C_pointer)

Fills the array with the next line of tab delimited values from the open file.

About

A 4D component with some basic file and folder utility methods

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages