EAFileUtil

Introduction

EAFileUtil is a library of standalone functions which query or manipulate files and directories.

Functionality present in EAFileUtil includes:

A list of all available functions is at the end of this file.

Example usage

We provide some example code for selected EAFileUtil functions here.

File::PatternExists:

bool PluginSystem::PluginsExist()
{
    eastl::fixed_string<char16_t, kMaxPathLength> pathPattern(mDirectory);
 
    pathPattern += L"*.plugin";
 
    return File::PatternExists(pathPattern.c_str());
}

File::GetTime:

bool FileChangeDetector::HasFileChanged(const char16_t* pFilePath)
{
    const time_t timeOfLastModification = File::GetTime(pFilePath, kFileTimeTypeLastModification);
 
    return (timeOfLastModification >= mTimeOfLastCheck);
}

Directory::Create:

bool Installer::CreateAudioDirectory()
{
    eastl::fixed_string<char16_t, kMaxPathLength> audioDirectory(mBaseDirectory);
    
    audioDirectory += L"Audio";
    audioDirectory += kFilePathSeparator;
 
    return Directory::Create(audioDirectory.c_str());
}

Directory::Copy:

bool Installer::InstallDataFiles()
{
    // Copy the DVD directory tree to the HD.
    return Directory::Copy(mHDDataDir.c_str(), mDVDDataDir.c_str(), true, false);
}

MakeTempPathName:

bool SuperBaseballApp::SaveGame(const char16_t* pSaveGameDirectoryPath, const char16_t* pSaveGameFileName)
{
    eastl::fixed_string<char16_t, kMaxPathLength> tempGamePath(kMaxPathLength - 1, 0);

    // Make a temp file name in the specified directory and with the extension ".tmp".
    if(MakeTempPathName(const_cast<char16_t*>(tempGamePath.data()), pSaveGameDirectoryPath, 
                         pSaveGameFileName, L".tmp"))
    {
        if(WriteGame(tempGamePath.c_str()))
        {
            eastl::fixed_string<char16_t, kMaxPathLength> saveGamePath(pSaveGameDirectoryPath);
            saveGamePath += pSaveGameFileName;

            File::Rename(tempGamePath.c_str(), saveGamePath.c_str(), true);
        }
        else
            File::Remove(tempGamePath.c_str());

        return true;
    }

    return false;
}

GetSpecialDirectory:

bool SuperBaseballApp::WritePrefs()
{
    eastl::fixed_string<char16_t, kMaxPathLength> prefsFilePath(kMaxPathLength - 1, 0);
    
    prefsFilePath.resize(GetSpecialDirectory(kSpecialDirectoryUserApplicationData, 
                                              const_cast<char16_t*>(prefsFilePath.data()), true));
    prefsFilePath += L"prefs.dat";

    WritePrefsFile(prefsFilePath.c_str());
}

Interface

Instead of display the header file contents here, we instead make a table that briefly shows the available functions. See EAFileUtil.h for more details and for any functions that may have been added since this writing.

Function Description
File::Exists Tells if a file exists.
File::PatternExists Tells if a file matching a given wildcard pattern exists.
File::Create Creates a file.
File::Remove Deletes a file.
File::Move Moves a file to a different location, can also act as a rename.
File::Rename Renames a file. Same as moving to same directory.
File::Copy Copies a file.
File::GetSize Gets the size of a file in bytes.
File::IsWritable Tells if a file can be opened for writing.
File::GetAttributes Gets the access attributes of a file.
File::SetAttributes Sets the access attributes of a file.
File::GetTime Gets the time of file creation, modification, etc.
File::SetTime Sets the time of file creation, modification, etc.
File::ResolveAlias Tells what file an alias file refers to.
   
Directory::Exists Tells if a directory exists.
Directory::EnsureExists Creates a directory if it doesn't already exist.
Directory::Create Creates a directory.
Directory::Remove Deletes a directory, optionally recursively.
Directory::Move Moves a directory to a different location, can also act as a rename.
Directory::Rename Renames a directory.
Directory::Copy Copies a directory, optionally recursively.
Directory::GetAttributes Gets the access attributes of a directory.
Directory::SetAttributes Sets the access attributes of a directory.
Directory::GetCurrentWorkingDirectory Gets the application's current working directory.
Directory::SetCurrentWorkingDirectory Sets the application's current working directory.
   
MakeTempPathName Creates a temporary file name.
GetTempDirectory Gets the directory used for temporary files.
SetTempDirectory Sets the directory used for temporary files.
GetDriveFreeSpace Gets free space of a given drive/volume.
GetDriveName Gets the name of a given drive/volume.
GetDriveSerialNumber Gets the serial number of a given drive/volume.
GetDriveTypeValue Gets the type of the drive/volume (e.g. fixed HD, DVD, network).
GetDriveInfo Gets miscellaneous information about the available drives/volumes available.
GetSpecialDirectory Gets uniquely assigned system directories, such as the user's document directory.