Classes | Enumerations | Functions | Variables
AppSecInc::File Namespace Reference

Win32 File support functions. More...

Classes

class  Process
 Win32 process support functions. More...
 

Enumerations

enum  DELETE_DIRECTORY_FLAGS {
  DELETE_DIRECTORY_FILES = 1, DELETE_DIRECTORY_FOLDERS = 2, DELETE_DIRECTORY_SUBDIRECTORIES = 4, DELETE_DIRECTORY_EMPTY = DELETE_DIRECTORY_FOLDERS | DELETE_DIRECTORY_SUBDIRECTORIES,
  DELETE_DIRECTORY_ALL = DELETE_DIRECTORY_FILES | DELETE_DIRECTORY_FOLDERS | DELETE_DIRECTORY_SUBDIRECTORIES
}
 
enum  FILESIZE_STRING_TYPE {
  FILESIZE_AUTO = 0, FILESIZE_BYTES = 2, FILESIZE_KBYTES = 3, FILESIZE_MBYTES = 4,
  FILESIZE_GBYTES = 5
}
 
enum  GET_FILES_FLAGS { GET_FILES_FILES = 1, GET_FILES_DIRECTORIES = 2, GET_FILES_RECURSIVE = 4, GET_FILES_ALL = GET_FILES_FILES | GET_FILES_DIRECTORIES | GET_FILES_RECURSIVE }
 

Functions

std::string GetTemporaryFileNameA ()
 Create a temporary file and return its name. More...
 
std::wstring GetTemporaryFileNameW ()
 
std::string GetTemporaryDirectoryA ()
 Get the location of the temporary directory. More...
 
std::wstring GetTemporaryDirectoryW ()
 
std::string GetModuleFileNameA (HINSTANCE h=NULL)
 Get the full path to the module's filename. More...
 
std::wstring GetModuleFileNameW (HINSTANCE h=NULL)
 
std::string GetModuleDirectoryA ()
 Get the full path (directory) of the module's filename. More...
 
std::wstring GetModuleDirectoryW ()
 
std::string GetFileDirectoryA (const std::string &path)
 Get the directory portion of a full path. More...
 
std::wstring GetFileDirectoryW (const std::wstring &path)
 
std::string GetFileNameA (const std::string &path)
 Get the filename portion of a full path. More...
 
std::wstring GetFileNameW (const std::wstring &path)
 
std::string GetCurrentDirectoryA ()
 Get the current directory. More...
 
std::wstring GetCurrentDirectoryW ()
 
bool FileExists (const std::string &filename)
 Check whether a file exists. More...
 
bool FileExists (const std::wstring &filename)
 
void FileDelete (const std::string &filename)
 Delete a file. More...
 
void FileDelete (const std::wstring &filename)
 
void FileCopy (const std::string &src, const std::string &dest, bool overwrite=true)
 Copy a file. More...
 
void FileCopy (const std::wstring &src, const std::wstring &dest, bool overwrite=true)
 
bool DirectoryExists (const std::string &path)
 Check whether a directory exists. More...
 
bool DirectoryExists (const std::wstring &path)
 
std::string DirectoryCreate (const std::string &path)
 Create a directory. More...
 
std::wstring DirectoryCreate (const std::wstring &path)
 
bool DirectoryDelete (const std::string &path, int flags=DELETE_DIRECTORY_ALL)
 Delete a directory. More...
 
bool DirectoryDelete (const std::wstring &path, int flags=DELETE_DIRECTORY_ALL)
 
long GetFileSize (const std::wstring &filename)
 Get file size. More...
 
long GetFileSize (const std::string &filename)
 
std::pair< std::string,
std::string > 
SizeToStringPairA (long size, FILESIZE_STRING_TYPE type=FILESIZE_AUTO, int precision=0)
 Convert a file size into a pair of strings. More...
 
std::pair< std::wstring,
std::wstring > 
SizeToStringPairW (long size, FILESIZE_STRING_TYPE type=FILESIZE_AUTO, int precision=0)
 
std::string SizeToStringA (long size, FILESIZE_STRING_TYPE type=FILESIZE_AUTO, int precision=0)
 Convert a file size into a string. More...
 
std::wstring SizeToStringW (long size, FILESIZE_STRING_TYPE type=FILESIZE_AUTO, int precision=0)
 
std::wstring DirectoryCombine (const std::wstring &dir, const std::wstring &file)
 Combine two directory paths and an optional file. More...
 
std::list< std::wstring > GetFiles (const std::wstring &path, const std::wstring &wildcard=L"*.*", int flags=GET_FILES_FILES)
 Get a list of files in a directory structure. More...
 
std::list< std::wstring > GetFiles (const std::wstring &path_and_wildcard, int flags)
 Get a list of files in a directory structure. More...
 
std::list< std::wstring > GetDirectoryFiles (const std::wstring &path, const std::wstring &wildcard=L"*.*")
 Get a list of file names in path. More...
 
void ReadToEnd (const std::wstring &filename, std::wstring &data)
 Read the entire contents of file. More...
 
void ReadToEnd (const std::wstring &filename, std::string &data)
 Read the entire contents of file. More...
 
void ReadToEnd (const std::wstring &filename, std::vector< char > &data)
 Read the entire contents of file. More...
 
bool ReadAndConvertToEnd (const std::wstring &filename, std::wstring &data)
 Read the entire contents of file and convert to UNICODE depending on the file marker. More...
 
void FileWrite (const std::wstring &filename, const std::vector< char > &data, DWORD dwShareMode=GENERIC_READ|GENERIC_WRITE, DWORD dwCreationDisposition=CREATE_ALWAYS, DWORD dwFlagsAndAttributes=FILE_ATTRIBUTE_NORMAL)
 Write data to a file. More...
 
void FileCreate (const std::wstring &filename, DWORD dwShareMode=GENERIC_READ|GENERIC_WRITE, DWORD dwCreationDisposition=CREATE_ALWAYS, DWORD dwFlagsAndAttributes=FILE_ATTRIBUTE_NORMAL)
 Create an empty file. More...
 
std::string GetParentDirectory (const std::string &path)
 Get the parent directory of a path. More...
 
std::wstring GetParentDirectory (const std::wstring &path)
 Get the parent directory of a path. More...
 
std::wstring GetSpecialFolderPath (int csidl, BOOL create=FALSE)
 Takes the CSIDL of a folder and returns the path. More...
 
bool IsAbsolutePath (const std::wstring &path)
 returns true if provided path is absolute, false otherwise More...
 

Variables

const long BYTE = 1
 
const long KBYTE = BYTE * 1024
 
const long MBYTE = KBYTE * 1024
 
const long GBYTE = MBYTE * 1024
 

Detailed Description

Win32 File support functions.

Enumeration Type Documentation

Enumerator
DELETE_DIRECTORY_FILES 
DELETE_DIRECTORY_FOLDERS 

delete files

DELETE_DIRECTORY_SUBDIRECTORIES 

delete folders

DELETE_DIRECTORY_EMPTY 

delete subdirectories

DELETE_DIRECTORY_ALL 

delete empty (sub)directories only

Enumerator
FILESIZE_AUTO 
FILESIZE_BYTES 

automatically adjust

FILESIZE_KBYTES 

byte(s)

FILESIZE_MBYTES 

Kb.

FILESIZE_GBYTES 

Mb.

Enumerator
GET_FILES_FILES 
GET_FILES_DIRECTORIES 

return files

GET_FILES_RECURSIVE 

return directory names

GET_FILES_ALL 

recurse into subdirectories

Function Documentation

std::wstring AppSecInc::File::DirectoryCombine ( const std::wstring &  dir,
const std::wstring &  file 
)

Combine two directory paths and an optional file.

std::string AppSecInc::File::DirectoryCreate ( const std::string &  path)

Create a directory.

Parameters
pathfull path to the directory to create
Returns
first path created

Create a directory with any subdirectories missing. This function will create subdirectories and will return the first directory actually created.

std::wstring AppSecInc::File::DirectoryCreate ( const std::wstring &  path)
bool AppSecInc::File::DirectoryDelete ( const std::string &  path,
int  flags = DELETE_DIRECTORY_ALL 
)

Delete a directory.

    \param path full path to the directory to delete
Parameters
flagsflags for directory deletion
Returns
true if directory (and all subdirectories and files) have been deleted, false otherwise
    Delete directories with subdirectories. Optionally delete files
and subdirectories. If flags is DELETE_DIRECTORY_FOLDERS deletes empty (sub)directories only. If an error occurs, the process aborts with an exception.
    No error is thrown if the directory doesn't exist or if it contains no files or subdirectories.
bool AppSecInc::File::DirectoryDelete ( const std::wstring &  path,
int  flags = DELETE_DIRECTORY_ALL 
)
bool AppSecInc::File::DirectoryExists ( const std::string &  path)

Check whether a directory exists.

Unlike Win32 ::PathFileExists this function fails when the parameter is not a directory (eg. a file) or on other errors (eg. access denied).

Parameters
pathfull path of the directory to check
Returns
true if directory exists, false otherwise
bool AppSecInc::File::DirectoryExists ( const std::wstring &  path)
void AppSecInc::File::FileCopy ( const std::string &  src,
const std::string &  dest,
bool  overwrite = true 
)

Copy a file.

Parameters
srcsource file
destdestination file
void AppSecInc::File::FileCopy ( const std::wstring &  src,
const std::wstring &  dest,
bool  overwrite = true 
)
void AppSecInc::File::FileCreate ( const std::wstring &  filename,
DWORD  dwShareMode = GENERIC_READ | GENERIC_WRITE,
DWORD  dwCreationDisposition = CREATE_ALWAYS,
DWORD  dwFlagsAndAttributes = FILE_ATTRIBUTE_NORMAL 
)

Create an empty file.

Parameters
dwShareModeshare mode
dwCreationDispositioncreation disposition
dwFlagsAndAttributesflags and attributes
void AppSecInc::File::FileDelete ( const std::string &  filename)

Delete a file.

Parameters
filenamefull path of the file to delete
void AppSecInc::File::FileDelete ( const std::wstring &  filename)
bool AppSecInc::File::FileExists ( const std::string &  filename)

Check whether a file exists.

Unlike Win32 ::PathFileExists this function fails when the parameter is not a file (eg. a directory) or on other errors (eg. access denied).

Parameters
filenamefull path of the file to check
Returns
true if file exists, false otherwise
bool AppSecInc::File::FileExists ( const std::wstring &  filename)
void AppSecInc::File::FileWrite ( const std::wstring &  filename,
const std::vector< char > &  data,
DWORD  dwShareMode = GENERIC_READ | GENERIC_WRITE,
DWORD  dwCreationDisposition = CREATE_ALWAYS,
DWORD  dwFlagsAndAttributes = FILE_ATTRIBUTE_NORMAL 
)

Write data to a file.

Parameters
datadata to write
dwShareModeshare mode
dwCreationDispositioncreation disposition
dwFlagsAndAttributesflags and attributes
std::string AppSecInc::File::GetCurrentDirectoryA ( )

Get the current directory.

Returns
current directory
std::wstring AppSecInc::File::GetCurrentDirectoryW ( )
std::list< std::wstring > AppSecInc::File::GetDirectoryFiles ( const std::wstring &  path,
const std::wstring &  wildcard = L"*.*" 
)

Get a list of file names in path.

Parameters
pathfull path
wildcardof files to find
Note
Unlike GetFiles, this function doesn't return the full path to the file(s).
std::string AppSecInc::File::GetFileDirectoryA ( const std::string &  path)

Get the directory portion of a full path.

Parameters
pathinput path
Returns
directory portion of the path
std::wstring AppSecInc::File::GetFileDirectoryW ( const std::wstring &  path)
std::string AppSecInc::File::GetFileNameA ( const std::string &  path)

Get the filename portion of a full path.

Parameters
pathinput path
Returns
file name portion of the path
std::wstring AppSecInc::File::GetFileNameW ( const std::wstring &  path)
std::list< std::wstring > AppSecInc::File::GetFiles ( const std::wstring &  path,
const std::wstring &  wildcard = L"*.*",
int  flags = GET_FILES_FILES 
)

Get a list of files in a directory structure.

Returns
a list of files and/or directories with or without subdirectories
Parameters
pathpath at which to start looking
flagscombination of GET_FILES_FLAGS
std::list< std::wstring > AppSecInc::File::GetFiles ( const std::wstring &  path_and_wildcard,
int  flags 
)

Get a list of files in a directory structure.

Returns
a list of files and/or directories with or without subdirectories
Parameters
path_and_wildcarda combination of path and wildcard at which to start looking
flagscombination of GET_FILES_FLAGS
long AppSecInc::File::GetFileSize ( const std::wstring &  filename)

Get file size.

Returns
file size in bytes, note that some directories may return a positive size
long AppSecInc::File::GetFileSize ( const std::string &  filename)
std::string AppSecInc::File::GetModuleDirectoryA ( )

Get the full path (directory) of the module's filename.

Returns
directory portion of the result from Win32 ::GetModuleFilename
std::wstring AppSecInc::File::GetModuleDirectoryW ( )
std::string AppSecInc::File::GetModuleFileNameA ( HINSTANCE  h = NULL)

Get the full path to the module's filename.

Returns
the result from Win32 ::GetModuleFilename
std::wstring AppSecInc::File::GetModuleFileNameW ( HINSTANCE  h = NULL)
std::string AppSecInc::File::GetParentDirectory ( const std::string &  path)

Get the parent directory of a path.

Parameters
pathexisting directory
Returns
parent directory, an empty string if path is empty and the same value if there's no parent directory
std::wstring AppSecInc::File::GetParentDirectory ( const std::wstring &  path)

Get the parent directory of a path.

Parameters
pathexisting directory
Returns
parent directory terminated by a backslash, an empty string if path is empty and the same value if there's no parent directory
std::wstring AppSecInc::File::GetSpecialFolderPath ( int  csidl,
BOOL  create = FALSE 
)

Takes the CSIDL of a folder and returns the path.

Parameters
csidla CSIDL value that identifies the folder whose path is to be retrieved
createIndicates whether the folder should be created if it does not already exist.
Returns
special folder path
std::string AppSecInc::File::GetTemporaryDirectoryA ( )

Get the location of the temporary directory.

Returns
name of the temporary directory
std::wstring AppSecInc::File::GetTemporaryDirectoryW ( )
std::string AppSecInc::File::GetTemporaryFileNameA ( )

Create a temporary file and return its name.

Returns
name of the temporary file
std::wstring AppSecInc::File::GetTemporaryFileNameW ( )
bool AppSecInc::File::IsAbsolutePath ( const std::wstring &  path)

returns true if provided path is absolute, false otherwise

bool AppSecInc::File::ReadAndConvertToEnd ( const std::wstring &  filename,
std::wstring &  data 
)

Read the entire contents of file and convert to UNICODE depending on the file marker.

Parameters
filenamepath to a file output, full contents of file in UNICODE format
Returns
true if UTF8 conversion has occurred
Remarks
Currently supports UTF-8 only.
void AppSecInc::File::ReadToEnd ( const std::wstring &  filename,
std::wstring &  data 
)

Read the entire contents of file.

Parameters
filenamepath to a file with non-UNICODE contents
Returns
full contents of file as a UNICODE string
void AppSecInc::File::ReadToEnd ( const std::wstring &  filename,
std::string &  data 
)

Read the entire contents of file.

Parameters
filenamepath to a file
Returns
full contents of file as an ANSI string
void AppSecInc::File::ReadToEnd ( const std::wstring &  filename,
std::vector< char > &  data 
)

Read the entire contents of file.

Parameters
filenamepath to a file
Returns
full contents of file
std::string AppSecInc::File::SizeToStringA ( long  size,
FILESIZE_STRING_TYPE  type = FILESIZE_AUTO,
int  precision = 0 
)

Convert a file size into a string.

Parameters
sizesize to convert
typetype of conversion
precisiondecimal precision
Returns
a string representation of a size, including its type
std::pair< std::string, std::string > AppSecInc::File::SizeToStringPairA ( long  size,
FILESIZE_STRING_TYPE  type = FILESIZE_AUTO,
int  precision = 0 
)

Convert a file size into a pair of strings.

Parameters
sizesize to convert
typetype of conversion
precisiondecimal precision
Returns
a pair of string representation of a size and its type
std::pair< std::wstring, std::wstring > AppSecInc::File::SizeToStringPairW ( long  size,
FILESIZE_STRING_TYPE  type = FILESIZE_AUTO,
int  precision = 0 
)
std::wstring AppSecInc::File::SizeToStringW ( long  size,
FILESIZE_STRING_TYPE  type = FILESIZE_AUTO,
int  precision = 0 
)

Variable Documentation

const long AppSecInc::File::BYTE = 1
const long AppSecInc::File::GBYTE = MBYTE * 1024
const long AppSecInc::File::KBYTE = BYTE * 1024
const long AppSecInc::File::MBYTE = KBYTE * 1024


© Application Security Inc. - All Rights Reserved http://msiext.codeplex.com