fFILESYSTEM


Quick Data

Header file:filesystem.h
Object name:fFILESYSTEM
Object index:1 of 1 Object

General Description

The fFILESYSTEM is a class that simply gets some information about the file system, and can also set/do some things filesystem related. This is a global class, and need not be created - although you still can if you so wish. To stop the global creation, define F_NOGLOBALFILESYS before you include the header file. The global object is called FileSys.


Methods


Prototype Description

bool CreateDir(char* Directory); This function creates a new directory with the specified name.
bool RemoveDir(char* Directory); This function removes the specified directory. The directory must be empty before you can remove it.
char* GetCurrDir(void); This function returns the name of the current directory.
void SetCurrDir(void); This function sets the current directory.
char* GetSysDir(void); This function returns the system directory. This directory may typically be C:\Windows\System.
char* GetWinDir(void); This function returns the windows directory. This directory may typically be C:\Windows, but do use this function to find out for sure.
char* Dir(char* FileSpec); This function starts a search for files with the specified FileSpec. An example of FileSpec would be "*.*" or "*.txt", both returning files in the current directory with the specified extentions. This function returns one filename. To retreive the next filename up until the end, please use the next function. To get more information about the file that you just found, please use the other functions following. If this function returns NULL, then there are no files matching FileSpec.
char* Dir(void); This function you will need to call each time you are ready to receive the next filename. When this function returns NULL, there are no more files to return, and the class will finalise the search..
int Dir_GetSize(void); This function returns the size of the last file retrieved.
int Dir_GetAttributes(void); This function returns the file attributes of the last file retrieved. It can be one or a mixture of the following styles: (taken from the Win32 SDK Reference manual)
  • FILE_ATTRIBUTE_ARCHIVE - The file is an archive file. Applications use this value to mark files for backup or removal.
  • FILE_ATTRIBUTE_COMPRESSED - The file or directory is compressed. For a file, this means that all of the data in the file is compressed. For a directory, this means that compression is the default for newly created files and subdirectories.
  • FILE_ATTRIBUTE_DIRECTORY - The file is a directory.
  • FILE_ATTRIBUTE_HIDDEN - The file is hidden. It is not included in an ordinary directory listing.
  • FILE_ATTRIBUTE_NORMAL - The file has no other attributes set. This value is valid only if used alone.
  • FILE_ATTRIBUTE_OFFLINE - The data of the file is not immediately available. Indicates that the file data has been physically moved to offline storage.
  • FILE_ATTRIBUTE_READONLY - The file is read-only. Applications can read the file but cannot write to it or delete it.
  • FILE_ATTRIBUTE_SYSTEM - The file is part of the operating system or is used exclusively by it.
  • FILE_ATTRIBUTE_TEMPORARY - The file is being used for temporary storage. Applications should write to the file only if absolutely necessary. Most of the file’s data remains in memory without being flushed to the media because the file will soon be deleted.
As mentioned above, this value can be a mixture of these values, which would have been mixed with the OR (|) operator. To see how to extract these values, please see the example code at the end of this document.
FILETIME* Dir_GetCreationTime(void); This function returns the creation time of the last file retrieved. This is just a 'number', and you'll have to use some other functions to get any meaning from this. Don't ask me what this means or how to use it, I don't know! Look up 'FILETIME' in an API reference if you want to - and see if you can make sense of it.
FILETIME* Dir_GetLastAccessTime(void); This function returns the time that the file was last accessed for the last retrieved file. Refer to the description for the above function in relation on what you can do with the returned value.
FILETIME* Dir_GetLastWriteTime(void); This function returns the last time that the file was written to for the last retreived file. Refer to the function two rows above for a description of what you can do with the returned value.

Sample Code

The following snippet gives a basic idea of how to use this component.


//Let's use a fFILESYSTEM....
//It's already a globally created class...

... = FileSys.GetCurrDir();

//Get the files from a directory.
//Get the first file...
File1 = FileSys.Dir("*.txt");
//Check to see if no files, quit if so...
if (File1 == NULL) return;
//Make a loop.
while (1 == 1) //Infinite loop...
      {
      //Get the next file...
      FileN = FileSys.Dir();
      //Check to see if it's the last file...
      if (FileN == NULL) break;
      //Get the size...
      int FileSize = FileSys.Dir_GetSize();
      //Check to see if it's read-only...
      if (FileSys.Dir_GetAttributes() & FILE_ATTRIBUTE_READONLY)
         {
         //File is read-only. See how to do that?
         }
      }

Back to indexThe FreeFoote Foundation Classes Documentation