ADTF  3.18.2
cFileSystem

File system class. More...

Public Types

enum  { ED_DEFAULT = 0x0 , ED_FILES = 0x1 , ED_DIRECTORIES = 0x2 }
 
enum  FilePermissionFlag {
  PERM_USR_RD = 0x0400 , PERM_USR_WR = 0x0200 , PERM_USR_EX = 0x0100 , PERM_GRP_RD = 0x0040 ,
  PERM_GRP_WR = 0x0020 , PERM_GRP_EX = 0x0010 , PERM_OTH_RD = 0x0004 , PERM_OTH_WR = 0x0002 ,
  PERM_OTH_EX = 0x0001 , PERM_SUID = 0x4000 , PERM_SGID = 0x2000 , PERM_SVTX = 0x1000
}
 File permission flags. More...
 

Static Public Member Functions

static tUInt32 GetFileAttrib (const cFilename &strFilename)
 Get the file attributes of a specified file. More...
 
static tResult ReadTextFile (const cFilename &strFilename, cString &strString, const tUInt32 &ui32OpenMode=cFile::OM_Read|cFile::OM_SharedRead|cFile::OM_SequentialAccess)
 This function reads a complete text file into a cString object. More...
 
static tResult WriteTextFile (const cFilename &strFilename, const cString &strString)
 This function creates a text file from an existing cString object. More...
 
static tBool Exists (const cFilename &strFilename)
 This function checks if a file or directory exists. More...
 
static tFileSize GetFileSize (const cFilename &strFilename)
 This function gets the size of a file in bytes. More...
 
static tBool IsFile (const cFilename &strFilename)
 This function checks if the specified filename points to a file. More...
 
static tBool IsDirectory (const cFilename &strFilename)
 This function checks if the specified filename points to a directory. More...
 
static tResult CreatePath (const cFilename &strDirName, tBool bRecursive=false)
 This function creates a directory. More...
 
static tBool IsReadOnly (const cFilename &strFilename)
 This function checks if a file is read-only. More...
 
static tResult SetReadOnly (const cFilename &strFilename, tBool bReadOnly=true)
 This function sets or removes the read-only flag for a file. More...
 
static tResult DelFile (const cFilename &strFilename)
 Deletes a File. More...
 
static tResult DelDirectory (const cFilename &strDirectory)
 Deletes a Directory. More...
 
static cFilename GetCurDirectory ()
 Returns the current working directory. More...
 
static tResult SetCurDirectory (const cFilename &strDirName)
 Changes the current working directory. More...
 
static cFilename GetAppDirectory ()
 Returns the directory where the executable resides. More...
 
static cFilename GetSysDirectory ()
 Returns the system directory (e.g. More...
 
static cFilename GetOwnModuleFileName ()
 The filename of the module (DLL, so, executable) calling this method. More...
 
static cFilename GetOwnModuleDirectory ()
 For instance a DLL or shared library file is loaded within another application. More...
 
static cFilename GetUserApplicationDirectory (const cString &strApplication=cString::Empty)
 Returns the application data directory of the current user. More...
 
static cFilename GetTempDirectory ()
 Returns the temp directory. More...
 
static tResult FileCopy (const cString &strFrom, const cString &strTo)
 Copies a file to another location. More...
 
static tResult FolderCopy (const cFilename &strFrom, const cFilename &strTo)
 Copies a folder recursively to another location. More...
 
static tResult Move (const cFilename &strFrom, const cFilename &strTo)
 Moves a folder or file. More...
 
static tUInt32 GetFilePermissions (const cFilename &strFilename)
 Returns the permission set of a file. More...
 
static tResult SetFilePermissions (const cFilename &strFilename, tUInt32 nPermissionMask)
 Sets the permission set of a file. More...
 
static tInt GetDefaultSectorSize ()
 Get the default sector size. More...
 
static tInt GetSectorSize (const cFilename &strFilename)
 Get the sector size of the filesystem that a specified file resides on. More...
 
static tVoidAllocPageAlignedMemory (tInt nSize, tInt nPageSize=0)
 Allocates memory that is page aligned. More...
 
static tResult FreePageAlignedMemory (tVoid *pMemory)
 Free memory that has been allocated using AllocPageAlignedMemory. More...
 
static tResult EnumDirectory (const cFilename &strDir, cStringList &lstFiles, tUInt32 ui32Flags=0)
 Lists all entries in a directory. More...
 
static tResult GetFreeDiskSpace (const tChar *strFolder, tUInt64 *pui64FreeBytes)
 Returns the free diskspace on the media that the given path resides on. More...
 
static tResult FindFiles (const cString &strPattern, cStringList &lstFiles)
 Search for files matching a specific pattern. More...
 
static tResult FindFolders (const cString &strPattern, cStringList &lstFolders)
 Searches for folders matching a specific pattern. More...
 
static tResult GetTimeAccess (const cFilename filename, A_UTILS_NS::cDateTime &dt)
 This function returns the last access time of the file. More...
 
static tResult GetTimeCreation (const cFilename filename, A_UTILS_NS::cDateTime &dt)
 This function returns the creation time of the file. More...
 
static tResult GetTimeChange (const cFilename filename, A_UTILS_NS::cDateTime &dt)
 This function returns the last change (write) time of the file. More...
 
static tInt GetLastErrorCode ()
 Gets the error code of the last failure. More...
 
static tResult RenameFilename (cFilename oldFileName, cFilename newFileName)
 The rename function shall change the name of a file. More...
 

Static Protected Attributes

static cFilename m_strLastBrowseDir
 currently not in use More...
 
static tUInt32 m_ui32DefaultSectorSize
 the default sector size of the system / drive / device
 

Detailed Description

Member Enumeration Documentation

◆ FilePermissionFlag

Member Function Documentation

◆ AllocPageAlignedMemory()

static tVoid* AllocPageAlignedMemory ( tInt  nSize,
tInt  nPageSize = 0 
)
static

Allocates memory that is page aligned.

Parameters
nSize[in] How much memory should be allocated (Bytes).
nPageSize[in] The size of a page, autodetected if = 0.
Returns
Returns a pointer to the allocated memory.

◆ CreatePath()

static tResult CreatePath ( const cFilename strDirName,
tBool  bRecursive = false 
)
static

This function creates a directory.

If the parent directory structure doesn't exist, the bRecursive option causes this to be created as well.

Note
This function will always return ERR_NOERROR if strDirName is empty because it considers this to be the current path which exists per definition. However, this is not checked.
Parameters
strDirName[in] Path or name of directory to be created.
bRecursive[in] Flag for creating the whole parent directory structure.
Returns
Standard Error Code.
Return values
ERR_EMPTYif path or name of directory is empty.
ERR_INVALID_FILEif a file with the same name already exists.
ERR_FAILEDif share does not exist and path could not be created.
ERR_NOERRORif succeeded or a directory with the same name already exists (it doesn't matter if the existing directory is empty or not).

◆ DelDirectory()

static tResult DelDirectory ( const cFilename strDirectory)
static

Deletes a Directory.

Parameters
strDirectory[in] name of the directory to be deleted.
Returns
Standard Error Code.
Return values
ERR_INVALID_FILEif cFileSystem::Exists() failed.
ERR_ACCESS_DENIEDif failed.
ERR_NOERRORif succeeded.
Remarks
Replaces: RemoveDirectory.

◆ DelFile()

static tResult DelFile ( const cFilename strFilename)
static

Deletes a File.

Parameters
strFilename[in] name of the file to be deleted.
Returns
Standard Error Code.
Return values
ERR_ACCESS_DENIEDif failed.
ERR_NOERRORif succeeded.
Remarks
Replaces: RemoveFile.

◆ EnumDirectory()

static tResult EnumDirectory ( const cFilename strDir,
cStringList lstFiles,
tUInt32  ui32Flags = 0 
)
static

Lists all entries in a directory.

Parameters
strDir[in] The directory.
lstFiles[out] The list of entries.
ui32Flags[in] Whether to list files (ED_FILES) or directories (ED_DIRECTORIES). Default is files only.
Return values
StandardResult Code.
ERR_INVALID_HANDLEif handle value is invalid.
ERR_NOERRORif succeeded.

◆ Exists()

static tBool Exists ( const cFilename strFilename)
static

This function checks if a file or directory exists.

Parameters
strFilename[in] Path of file or directory to be checked for.
Returns
Standard Error Code.
Return values
ERR_INVALID_FILEif file does net exists.
ERR_NOERRORif succeeded.

◆ FileCopy()

static tResult FileCopy ( const cString strFrom,
const cString strTo 
)
static

Copies a file to another location.

Parameters
strFrom[in] The source filename.
strTo[in] The destination filename.
Return values
StandardResult Code.
ERR_OPEN_FAILEDif source & destination file could not be open.
ERR_MEMORYif buffer could not be created.
ERR_FAILEDfile could not be copied.
ERR_NOERRORif succeeded.

◆ FindFiles()

static tResult FindFiles ( const cString strPattern,
cStringList lstFiles 
)
static

Search for files matching a specific pattern.

The pattern strPattern can be a relative or absolute filepath. The pattern has to be of one of the following forms:

  • root/a.file : returns a.file, if exists
  • root/*.file : match all files with ending .file in the root folder
  • root/* : returns all files in root folder (no recursion!)
  • root/*.* : same as root/*
  • root/*/a.file : search for a.file in every subfolder of root (no recursion!)
  • root/**/*.* : returns all files in root and every subfolder recursively!
  • root/**/* : same as root/**/*.*
  • root/**/sub/a.file : search for sub/a.file in every subfolder of root recursively
  • root/a*cc.file : use * as a wildcard within filenames.
Parameters
strPattern[in] The pattern to match.
lstFiles[out] The list of found files.
Return values
ERR_NOERRORif files are found,
ERR_NOT_FOUNDotherwise.

◆ FindFolders()

static tResult FindFolders ( const cString strPattern,
cStringList lstFolders 
)
static

Searches for folders matching a specific pattern.

Wildcard * is the only one allowed.

Parameters
strPattern[in] The pattern to match.
lstFolders[out] The list of found folders.
Return values
ERR_NOERRORif folders are found,
ERR_NOT_FOUNDotherwise.

◆ FolderCopy()

static tResult FolderCopy ( const cFilename strFrom,
const cFilename strTo 
)
static

Copies a folder recursively to another location.

Parameters
strFrom[in] The source folder.
strTo[in] The destination filename.
Return values
StandardResult Code.
ERR_PATH_NOT_FOUNDif copy folder is no directory.
ERR_OPEN_FAILEDif source & destination file could not be open.
ERR_MEMORYif buffer could not be created.
ERR_FAILEDfile could not be copied.
ERR_NOERRORif succeeded.

◆ FreePageAlignedMemory()

static tResult FreePageAlignedMemory ( tVoid pMemory)
static

Free memory that has been allocated using AllocPageAlignedMemory.

Parameters
pMemory[in] Pointer the the allocated memory.
Return values
StandardResult Code.
ERR_MEMORYif memory could not be released.
ERR_NOERRORif succeeded.

◆ GetAppDirectory()

static cFilename GetAppDirectory ( )
static

Returns the directory where the executable resides.

Returns
The directory where the executable resides without a trailing slash.

◆ GetCurDirectory()

static cFilename GetCurDirectory ( )
static

Returns the current working directory.

Note
the trailing slash is here to remain compatible with older releases.
Returns
The current working directory WITH a trailing slash.

◆ GetDefaultSectorSize()

static tInt GetDefaultSectorSize ( )
static

Get the default sector size.

Returns
The default sector size.

◆ GetFileAttrib()

static tUInt32 GetFileAttrib ( const cFilename strFilename)
static

Get the file attributes of a specified file.

Parameters
strFilename[in] The filename.
Returns
The bit mask of the attributes.
See also
cFileAttributes

◆ GetFilePermissions()

static tUInt32 GetFilePermissions ( const cFilename strFilename)
static

Returns the permission set of a file.

Currently only implemented for Linux.

Parameters
strFilename[in] The filename.
See also
FilePermissionFlag
SetFilePermissions
SetReadOnly
Returns
The permission set of a file. If executed under windows, this returns 0x0777 which translate into all rights if the specified file exists. If the specified file does not exist or an error occured, 0xFFFFFFFF is returned.

◆ GetFileSize()

static tFileSize GetFileSize ( const cFilename strFilename)
static

This function gets the size of a file in bytes.

Note
On Windows, this function only works if the requested file is not already opened by cFile::Open().
Parameters
strFilename[in] name of the file
Returns
Returns the size of the file in bytes.
Returns tFalse if failed.

◆ GetFreeDiskSpace()

static tResult GetFreeDiskSpace ( const tChar strFolder,
tUInt64 pui64FreeBytes 
)
static

Returns the free diskspace on the media that the given path resides on.

Parameters
strFolder[in] The pathname. Must be absolute!
pui64FreeBytes[out] The free space in bytes, or ERR_INVALID_ARG, ERR_FAILED in case of failure or if strFolder was nullptr.
Return values
StandardResult Code.
ERR_INVALID_ARGif strFolder is nullptr.
ERR_FAILEDif free disk space could not be calculated.
ERR_NOERRORif succeeded.

◆ GetLastErrorCode()

static tInt GetLastErrorCode ( )
static

Gets the error code of the last failure.

Returns
The error code of the last failure.

◆ GetOwnModuleDirectory()

static cFilename GetOwnModuleDirectory ( )
static

For instance a DLL or shared library file is loaded within another application.

This function - called within the DLL or shared library file - returns the directory where the file resides in the file system. In other words: if called within a DLL or shared library file, it returns the own file system path of the file itself.

Returns
The directory of a loaded DLL or shared library file without a trailing slash.

◆ GetOwnModuleFileName()

static cFilename GetOwnModuleFileName ( )
static

The filename of the module (DLL, so, executable) calling this method.

Returns
The filename of the module calling this method.

◆ GetSectorSize()

static tInt GetSectorSize ( const cFilename strFilename)
static

Get the sector size of the filesystem that a specified file resides on.

Parameters
strFilename[in] The filename.
Returns
The sector size.

◆ GetSysDirectory()

static cFilename GetSysDirectory ( )
static

Returns the system directory (e.g.

system32 or /etc on unix).

Returns
The system directory without a trailing slash.

◆ GetTempDirectory()

static cFilename GetTempDirectory ( )
static

Returns the temp directory.

Returns
The temp directory without a trailing slash.

◆ GetTimeAccess()

static tResult GetTimeAccess ( const cFilename  filename,
A_UTILS_NS::cDateTime dt 
)
static

This function returns the last access time of the file.

Parameters
dtA_UTILS_NS::cDateTime of the last access
filenamecFilename of the file to be checked
Return values
OKif the time has been retrieved
ERR_INVALID_ARGif filename is empty
ERR_UNKNOWNif time cannot be read

◆ GetTimeChange()

static tResult GetTimeChange ( const cFilename  filename,
A_UTILS_NS::cDateTime dt 
)
static

This function returns the last change (write) time of the file.

Parameters
dtA_UTILS_NS::cDateTime of the last access
filenamecFilename of the file to be checked
Return values
OKif the time has been retrieved
ERR_INVALID_ARGif filename is empty
ERR_UNKNOWNif time cannot be read;

◆ GetTimeCreation()

static tResult GetTimeCreation ( const cFilename  filename,
A_UTILS_NS::cDateTime dt 
)
static

This function returns the creation time of the file.

Parameters
dtA_UTILS_NS::cDateTime of the last access
filenamecFilename of the file to be checked
Return values
OKif the time has been retrieved
ERR_INVALID_ARGif filename is empty
ERR_UNKNOWNif time cannot be read;

◆ GetUserApplicationDirectory()

static cFilename GetUserApplicationDirectory ( const cString strApplication = cString::Empty)
static

Returns the application data directory of the current user.

Parameters
[in]strApplicationadditional path to be added to the user directory
Returns
The application data directory without a trailing slash.

◆ IsDirectory()

static tBool IsDirectory ( const cFilename strFilename)
static

This function checks if the specified filename points to a directory.

Parameters
strFilename[in] Path of directory to be checked for.
Returns
Returns true, if the specified object is a directory, otherwise false.

◆ IsFile()

static tBool IsFile ( const cFilename strFilename)
static

This function checks if the specified filename points to a file.

Parameters
strFilename[in] Path of file to be checked for.
Returns
Returns tTrue, if the specified object is a file, otherwise tFalse.

◆ IsReadOnly()

static tBool IsReadOnly ( const cFilename strFilename)
static

This function checks if a file is read-only.

Parameters
strFilename[in] Path of file to be checked.
Returns
Returns tTrue, if the file was modified, otherwise false.

◆ Move()

static tResult Move ( const cFilename strFrom,
const cFilename strTo 
)
static

Moves a folder or file.

Parameters
strFrom[in] The source filename.
strTo[in] The destination filename.
Return values
StandardResult Code.
ERR_PATH_NOT_FOUNDif folder could not be copied.
ERR_FILE_NOT_FOUNDif file could not be copied.
ERR_NOERRORif succeeded.

◆ ReadTextFile()

static tResult ReadTextFile ( const cFilename strFilename,
cString strString,
const tUInt32 ui32OpenMode = cFile::OM_Read|cFile::OM_SharedRead|cFile::OM_SequentialAccess 
)
static

This function reads a complete text file into a cString object.

Parameters
strFilename[in] Path of file to be read.
strString[in] cString object to be filled.
ui32OpenMode[in] Open Mode of the File see cFile::tOpenMode (should be at least cFile::OM_Read)
Returns
Standard Error Code.
Return values
ERR_INVALID_FLAGSif ui32OpenMode isn't at least cFile::OM_Read or cFile::OM_SequentialAccess, otherwise ERR_OPEN_FAILED.
ERR_OUT_OF_RANGEif string buffer is on invalid position.
ERR_NOERRORif succeeded.

◆ RenameFilename()

static tResult RenameFilename ( cFilename  oldFileName,
cFilename  newFileName 
)
static

The rename function shall change the name of a file.

Parameters
oldFileNameThe old argument points to the pathname of the file to be renamed
newFileNameThe new argument points to the new pathname of the file
Return values
StandardResult Code.
ERR_UNKNOWNif file could not be renamed.
ERR_NOERRORif succeeded.

◆ SetCurDirectory()

static tResult SetCurDirectory ( const cFilename strDirName)
static

Changes the current working directory.

Parameters
strDirName[in] The path to the new working directory.
Returns
Standard Error Code.
Return values
ERR_PATH_NOT_FOUNDif directory was not found.
ERR_FAILEDif current directory could not be set.
ERR_NOERRORif succeeded.

◆ SetFilePermissions()

static tResult SetFilePermissions ( const cFilename strFilename,
tUInt32  nPermissionMask 
)
static

Sets the permission set of a file.

Currently only implemented for Linux.

Parameters
strFilename[in] The filename.
nPermissionMask[in] The new permission set.
See also
FilePermissionFlag
GetFilePermissions
Remarks
Windows: Always returns ERR_NOT_IMPL.
Return values
StandardResult Code.
ERR_PATH_MEMORYif memory problem occours.
ERR_FAILEDif PermissionMask failed.
ERR_NOERRORif succeeded.

◆ SetReadOnly()

static tResult SetReadOnly ( const cFilename strFilename,
tBool  bReadOnly = true 
)
static

This function sets or removes the read-only flag for a file.

Parameters
strFilename[in] Path of file to be modified.
bReadOnly[in] Set or remove the read only flag.
Returns
Standard Error Code.
Return values
ERR_FAILEDif set read only failed.
ERR_NOERRORif succeeded.

◆ WriteTextFile()

static tResult WriteTextFile ( const cFilename strFilename,
const cString strString 
)
static

This function creates a text file from an existing cString object.

Parameters
strFilename[in] Path of file to be written.
strString[in] cString object as data source.
Returns
Standard Error Code.
Return values
ERR_OPEN_FAILEDif cFile::OM_Write failed
ERR_NOERRORif succeeded.

Member Data Documentation

◆ m_strLastBrowseDir

cFilename m_strLastBrowseDir
staticprotected