File fhFileUtils.lua
Functions
copyFile (sPath, sDestination) | Copies an existing file and returns true if file copied OK |
copyFolder (sPath, sDestination) | Copies an existing folder and returns true if folder copied OK |
createFolder (sPath) | Creates a folder and returns true if folder created |
createTextFile (sPath, bOverwrite, bUnicode, sContents, iBits) | Creates a text file with optional contents and returns true if file created |
deleteFile (sPath) | Deletes existing file and returns true if file deleted |
deleteFolder (sPath) | Deletes a folder and all its contents and returns true if folder deleted |
fileExists (sPath) | Returns true if specified file exists |
fileGetContents (sFileName) | Loads the content of any existing file into a string. |
filePutContents (sFileName, sContents) | Saves the content a string to a file. |
folderExists (sPath) | Returns true if specified folder exists |
getFolderContents (sPath, bRecurse) | Return table of all files and folders in a specified folder. |
getParent (sPath) | Returns Parent folder for Path Provided |
moveFile (sPath, sDestination) | Moves an existing file and returns true if file moved OK. |
moveFolder (sPath, sDestination) | Moves an existing folder and returns true if moved OK |
readTextFile (sPath, bUnicode, iBits) | Reads an existing text file and returns a string of the contents Not intended for use with large files (> 20Mb) |
renameFile (sPath, sNewName) | Renames an existing file in its current location and returns true if file renamed |
renameFolder (sPath, sNewName) | Renames an existing folder in its current location and returns true if folder renamed |
splitPath (sPath) | Returns table of Path Parts drive=drive letter with colon, abs_path=fully resolved path, parent = parent folder,filename= file name excluding path,basename=file name excluding path and extension,ext=extension Notes: path is not validated only split; network file paths are not supported. |
Functions
- copyFile (sPath, sDestination)
-
Copies an existing file and returns true if file copied OK
Parameters:
-
sPath
: Full File Path -
sDestination
: Full File Path
Return value:
- True if file copied
-
- copyFolder (sPath, sDestination)
-
Copies an existing folder and returns true if folder copied OK
Parameters:
-
sPath
: Full Folder Path -
sDestination
: Full Folder Path
Return value:
- True if folder copied
-
- createFolder (sPath)
-
Creates a folder and returns true if folder created
Parameters:
-
sPath
: Full Folder Path
Return value:
- True if folder created
-
- createTextFile (sPath, bOverwrite, bUnicode, sContents, iBits)
-
Creates a text file with optional contents and returns true if file created
Parameters:
-
sPath
: Full File Path -
bOverwrite
: True if existing file can be overwritten. Defaults to true -
bUnicode
: True if file should be a Unicode file. Defaults to false (ASCII file) -
sContents
: Optional contents to be written to file. Defaults to an empty string -
iBits
: 8 for a UTF8 file or 16 for a UTF16 file. Defaults to 8 (UTF8)
Return value:
- boolean True if file created
-
- deleteFile (sPath)
-
Deletes existing file and returns true if file deleted
Parameters:
-
sPath
: Full File Path
Return value:
- True if file deleted
-
- deleteFolder (sPath)
-
Deletes a folder and all its contents and returns true if folder deleted
Parameters:
-
sPath
: Full Folder Path
Return value:
- True if folder deleted
-
- fileExists (sPath)
-
Returns true if specified file exists
Parameters:
-
sPath
: Full File Path
Return value:
- True if file exists
-
- fileGetContents (sFileName)
-
Loads the content of any existing file into a string. It is read as binary so can be used for graphics or other binary files. For text files it is recommended to use the readTextFile Note: does not handle utf8 file names.
Parameters:
-
sFileName
: Filename with path
Return value:
- string File Contents
-
- filePutContents (sFileName, sContents)
-
Saves the content a string to a file. Note: does not handle utf8 file names.
Parameters:
-
sFileName
: Filename with path -
sContents
: string to write
-
- folderExists (sPath)
-
Returns true if specified folder exists
Parameters:
-
sPath
: Full Folder Path
Return value:
- True if folder exists
-
- getFolderContents (sPath, bRecurse)
-
Return table of all files and folders in a specified folder. For each item the type,path,shortname, shortpath, created date,modified date,size and attributes are returned in a table.
Parameters:
-
sPath
: Full Folder Path -
bRecurse
: boolean Recurse subfolders
Return value:
- Table of Results or False if specified folder not found
-
- getParent (sPath)
-
Returns Parent folder for Path Provided
Parameters:
-
sPath
: Full File or Folder Path
Return value:
- Path of Parent Folder or False if path not found
-
- moveFile (sPath, sDestination)
-
Moves an existing file and returns true if file moved OK. Test for a file with the same name in the destination folder before calling this function.
Parameters:
-
sPath
: Full File Path -
sDestination
: Full File Path
Return value:
- True if file moved
-
- moveFolder (sPath, sDestination)
-
Moves an existing folder and returns true if moved OK
Parameters:
-
sPath
: Full Folder Path -
sDestination
: Full Folder Path
Return value:
- True if folder moved
-
- readTextFile (sPath, bUnicode, iBits)
-
Reads an existing text file and returns a string of the contents Not intended for use with large files (> 20Mb)
Parameters:
-
sPath
: Full File Path -
bUnicode
: True if file is a Unicode file. Defaults to false (ASCII file) -
iBits
: 8 for a UTF8 file or 16 for a UTF16 file. Defaults to 8 (UTF8)
Return value:
- string Contents of the file or false if the file doesn't exist
-
- renameFile (sPath, sNewName)
-
Renames an existing file in its current location and returns true if file renamed
Parameters:
-
sPath
: Full File Path -
sNewName
: New File Name including Extension
Return value:
- True if file renamed
-
- renameFolder (sPath, sNewName)
-
Renames an existing folder in its current location and returns true if folder renamed
Parameters:
-
sPath
: Full Folder Path -
sNewName
: New Folder Name
Return value:
- True if folder renamed
-
- splitPath (sPath)
-
Returns table of Path Parts
drive=drive letter with colon, abs_path=fully resolved path, parent = parent folder,filename= file name excluding path,basename=file name excluding path and extension,ext=extension
Notes: path is not validated only split; network file paths are not supported.Parameters:
-
sPath
: Full File or Folder Path (excludng network file paths)
Return value:
- Path Elements table
-