File.h
Go to the documentation of this file.
1 #pragma once
2 
3 namespace AppSecInc
4 {
6  namespace File
7  {
12  std::string GetTemporaryFileNameA();
13  std::wstring GetTemporaryFileNameW();
14 
19  std::string GetTemporaryDirectoryA();
20  std::wstring GetTemporaryDirectoryW();
21 
26  std::string GetModuleFileNameA(HINSTANCE h = NULL);
27  std::wstring GetModuleFileNameW(HINSTANCE h = NULL);
28 
33  std::string GetModuleDirectoryA();
34  std::wstring GetModuleDirectoryW();
35 
41  std::string GetFileDirectoryA(const std::string& path);
42  std::wstring GetFileDirectoryW(const std::wstring& path);
43 
49  std::string GetFileNameA(const std::string& path);
50  std::wstring GetFileNameW(const std::wstring& path);
51 
56  std::string GetCurrentDirectoryA();
57  std::wstring GetCurrentDirectoryW();
58 
67  bool FileExists(const std::string& filename);
68  bool FileExists(const std::wstring& filename);
69 
74  void FileDelete(const std::string& filename);
75  void FileDelete(const std::wstring& filename);
76 
82  void FileCopy(const std::string& src, const std::string& dest, bool overwrite = true);
83  void FileCopy(const std::wstring& src, const std::wstring& dest, bool overwrite = true);
84 
93  bool DirectoryExists(const std::string& path);
94  bool DirectoryExists(const std::wstring& path);
95 
104  std::string DirectoryCreate(const std::string& path);
105  std::wstring DirectoryCreate(const std::wstring& path);
106 
108  {
114  };
115 
128  bool DirectoryDelete(const std::string& path, int flags = DELETE_DIRECTORY_ALL);
129  bool DirectoryDelete(const std::wstring& path, int flags = DELETE_DIRECTORY_ALL);
130 
135  long GetFileSize(const std::wstring& filename);
136  long GetFileSize(const std::string& filename);
137 
139  {
145  };
146 
147  const long BYTE = 1;
148  const long KBYTE = BYTE * 1024;
149  const long MBYTE = KBYTE * 1024;
150  const long GBYTE = MBYTE * 1024;
151 
159  std::pair<std::string, std::string> SizeToStringPairA(long size, FILESIZE_STRING_TYPE type = FILESIZE_AUTO, int precision = 0);
160  std::pair<std::wstring, std::wstring> SizeToStringPairW(long size, FILESIZE_STRING_TYPE type = FILESIZE_AUTO, int precision = 0);
161 
169  std::string SizeToStringA(long size, FILESIZE_STRING_TYPE type = FILESIZE_AUTO, int precision = 0);
170  std::wstring SizeToStringW(long size, FILESIZE_STRING_TYPE type = FILESIZE_AUTO, int precision = 0);
171 
175  std::wstring DirectoryCombine(const std::wstring& dir, const std::wstring& file);
176 
178  {
183  };
184 
191  std::list<std::wstring> GetFiles(const std::wstring& path, const std::wstring& wildcard = L"*.*", int flags = GET_FILES_FILES);
192 
199  std::list<std::wstring> GetFiles(const std::wstring& path_and_wildcard, int flags);
200 
207  std::list<std::wstring> GetDirectoryFiles(const std::wstring& path, const std::wstring& wildcard = L"*.*");
208 
214  void ReadToEnd(const std::wstring& filename, std::wstring& data);
215 
221  void ReadToEnd(const std::wstring& filename, std::string& data);
222 
228  void ReadToEnd(const std::wstring& filename, std::vector<char>& data);
229 
231  static unsigned char utf8_bom[] = { 0xef, 0xbb, 0xbf };
232 
240  bool ReadAndConvertToEnd(const std::wstring& filename, std::wstring& data);
241 
249  void FileWrite(
250  const std::wstring& filename,
251  const std::vector<char>& data,
252  DWORD dwShareMode = GENERIC_READ | GENERIC_WRITE,
253  DWORD dwCreationDisposition = CREATE_ALWAYS,
254  DWORD dwFlagsAndAttributes = FILE_ATTRIBUTE_NORMAL);
255 
262  void FileCreate(
263  const std::wstring& filename,
264  DWORD dwShareMode = GENERIC_READ | GENERIC_WRITE,
265  DWORD dwCreationDisposition = CREATE_ALWAYS,
266  DWORD dwFlagsAndAttributes = FILE_ATTRIBUTE_NORMAL);
267 
273  std::string GetParentDirectory(const std::string& path);
274 
275 
281  std::wstring GetParentDirectory(const std::wstring& path);
282 
289  std::wstring GetSpecialFolderPath(int csidl, BOOL create = FALSE);
290 
292  bool IsAbsolutePath(const std::wstring& path);
293  }
294 }
std::wstring GetModuleFileNameW(HINSTANCE h=NULL)
Definition: File.cpp:77
std::string GetTemporaryDirectoryA()
Get the location of the temporary directory.
Definition: File.cpp:331
long GetFileSize(const std::wstring &filename)
Get file size.
Definition: File.cpp:316
std::string DirectoryCreate(const std::string &path)
Create a directory.
Definition: File.cpp:457
DELETE_DIRECTORY_FLAGS
Definition: File.h:107
bool ReadAndConvertToEnd(const std::wstring &filename, std::wstring &data)
Read the entire contents of file and convert to UNICODE depending on the file marker.
Definition: File.cpp:390
byte(s)
Definition: File.h:142
GET_FILES_FLAGS
Definition: File.h:177
std::wstring GetFileNameW(const std::wstring &path)
Definition: File.cpp:49
bool DirectoryDelete(const std::string &path, int flags=DELETE_DIRECTORY_ALL)
Delete a directory.
Definition: File.cpp:489
std::string GetParentDirectory(const std::string &path)
Get the parent directory of a path.
Definition: File.cpp:635
automatically adjust
Definition: File.h:141
void FileDelete(const std::string &filename)
Delete a file.
Definition: File.cpp:149
const long GBYTE
Definition: File.h:150
const long MBYTE
Definition: File.h:149
std::pair< std::wstring, std::wstring > SizeToStringPairW(long size, FILESIZE_STRING_TYPE type=FILESIZE_AUTO, int precision=0)
Definition: File.cpp:572
delete empty (sub)directories only
Definition: File.h:113
delete subdirectories
Definition: File.h:112
void ReadToEnd(const std::wstring &filename, std::wstring &data)
Read the entire contents of file.
Definition: File.cpp:351
std::string SizeToStringA(long size, FILESIZE_STRING_TYPE type=FILESIZE_AUTO, int precision=0)
Convert a file size into a string.
Definition: File.cpp:608
std::wstring GetTemporaryDirectoryW()
Definition: File.cpp:341
std::string GetFileDirectoryA(const std::string &path)
Get the directory portion of a full path.
Definition: File.cpp:22
delete folders
Definition: File.h:111
std::string GetCurrentDirectoryA()
Get the current directory.
Definition: File.cpp:619
FILESIZE_STRING_TYPE
Definition: File.h:138
std::wstring DirectoryCombine(const std::wstring &dir, const std::wstring &file)
Combine two directory paths and an optional file.
Definition: File.cpp:173
std::string GetModuleFileNameA(HINSTANCE h=NULL)
Get the full path to the module&#39;s filename.
Definition: File.cpp:68
std::wstring GetCurrentDirectoryW()
Definition: File.cpp:627
bool IsAbsolutePath(const std::wstring &path)
returns true if provided path is absolute, false otherwise
Definition: File.cpp:657
recurse into subdirectories
Definition: File.h:182
std::wstring GetSpecialFolderPath(int csidl, BOOL create=FALSE)
Takes the CSIDL of a folder and returns the path.
Definition: File.cpp:647
return files
Definition: File.h:180
Definition: File.h:140
std::wstring GetTemporaryFileNameW()
Definition: File.cpp:13
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.
Definition: File.cpp:564
std::wstring GetFileDirectoryW(const std::wstring &path)
Definition: File.cpp:31
std::list< std::wstring > GetDirectoryFiles(const std::wstring &path, const std::wstring &wildcard=L"*.*")
Get a list of file names in path.
Definition: File.cpp:212
std::wstring GetModuleDirectoryW()
Definition: File.cpp:63
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.
Definition: File.cpp:441
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.
Definition: File.cpp:253
Mb.
Definition: File.h:144
return directory names
Definition: File.h:181
bool DirectoryExists(const std::string &path)
Check whether a directory exists.
Definition: File.cpp:117
const long KBYTE
Definition: File.h:148
std::string GetFileNameA(const std::string &path)
Get the filename portion of a full path.
Definition: File.cpp:40
std::string GetModuleDirectoryA()
Get the full path (directory) of the module&#39;s filename.
Definition: File.cpp:58
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.
Definition: File.cpp:415
Kb.
Definition: File.h:143
std::wstring SizeToStringW(long size, FILESIZE_STRING_TYPE type=FILESIZE_AUTO, int precision=0)
Definition: File.cpp:613
delete files
Definition: File.h:110
Definition: File.h:179
bool FileExists(const std::string &filename)
Check whether a file exists.
Definition: File.cpp:86
std::string GetTemporaryFileNameA()
Create a temporary file and return its name.
Definition: File.cpp:4
const long BYTE
Definition: File.h:147
void FileCopy(const std::string &src, const std::string &dest, bool overwrite=true)
Copy a file.
Definition: File.cpp:161


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