nux-1.14.0
|
Public Member Functions | |
int | Copy (const TCHAR *InDestFile, const TCHAR *InSrcFile, bool OverWriteExisting, bool OverWriteReadOnly, NFileTransferMonitor *Monitor) |
bool | MakeDirectory (const TCHAR *Path, bool CreateCompletePath=false) |
bool | DeleteDirectory (const TCHAR *Path, bool DeleteContentFirst=false) |
Delete directory. | |
bool | Move (const TCHAR *Dest, const TCHAR *Src, bool OverWriteExisting=true, bool OverWriteReadOnly=false, NFileTransferMonitor *Monitor=NULL) |
int | CreateUniqueFileName (const TCHAR *Filename, const TCHAR *Extension, NString &OutputFilename, unsigned int BaseIndex=0xffffffff) |
bool | IsDrive (const TCHAR *Path) |
Definition at line 168 of file NFileManagerGeneric.h.
int nux::NFileManagerGeneric::CreateUniqueFileName | ( | const TCHAR * | Filename, |
const TCHAR * | Extension, | ||
NString & | OutputFilename, | ||
unsigned int | BaseIndex = 0xffffffff |
||
) | [virtual] |
Creates a unique file name. The format of the name is "DirectoryPath/BaseName####.Extension" where #### is a 4-digit number in [0, 9999]. The new name is unique and does not exist in the path directory. The function returns the value of the index created for the new file name or -1 if none could be found. The return value can be saved and passed the he next call to CreateUniqueFileName in order to speed up the search. Example usage: Create a new file name for of form DirectoryPath/Filename####.ext CreateUniqueFileName(TEXT("DirectoryPath/Filename"), TEXT("ext"), Output);
Filename | Filename with optional path. |
Extension | Extension. |
OutputFilename | New filename. |
BaseIndex | Base for index search. |
Implements nux::NFileManager.
Definition at line 233 of file NFileManagerGeneric.cpp.
{ nuxAssert (Filename); nuxAssert (Extension); NString FullPath (Filename); const t_size IndexMarker = FullPath.Length(); // Marks location of the four-digit index. FullPath += TEXT ("0000."); FullPath += Extension; // Iterate over indices, searching for a file that doesn't exist. for (DWORD i = BaseIndex + 1 ; i < 10000 ; ++i) { FullPath[IndexMarker ] = i / 1000 + TEXT ('0'); FullPath[IndexMarker+1] = (i / 100) % 10 + TEXT ('0'); FullPath[IndexMarker+2] = (i / 10) % 10 + TEXT ('0'); FullPath[IndexMarker+3] = i % 10 + TEXT ('0'); if (GFileManager.FileSize (FullPath.GetTCharPtr() ) == -1) { // The file doesn't exist; output success. OutputFilename = FullPath; return static_cast<int> (i); } } // Can't find an empty filename slot with index in (StartVal, 9999]. return -1; }
bool nux::NFileManagerGeneric::DeleteDirectory | ( | const TCHAR * | Path, |
bool | DeleteContentFirst = false |
||
) | [virtual] |
Delete directory.
Delete a Directory. If DeleteContent is true, The content of the directory is deleted before the directory itself;
Path | Path of the directory |
DeleteContentFirst | Delete the content of the directory before deleting the directory itself. |
Implements nux::NFileManager.
Reimplemented in nux::NFileManagerGNU.
Definition at line 183 of file NFileManagerGeneric.cpp.
{ nuxAssert (DeleteContentFirst); nuxAssert (Path != NULL); t_size PathLength = StringLength (Path); if (PathLength == 0) return false; NString WildcardPath = NString (Path); if ( (WildcardPath[PathLength - 1] != NUX_BACKSLASH_CHAR) && (WildcardPath[PathLength - 1] != NUX_SLASH_CHAR) ) WildcardPath += NUX_BACKSLASH_CHAR; WildcardPath += TEXT ("*"); std::vector<NString> List; FindFiles (List, *WildcardPath, 1, 0); for (t_u32 i = 0; i < List.size(); i++) { if (!Delete (* (NString (Path) + NUX_BACKSLASH_CHAR + List[i]), 1) ) return 0; } List.clear(); FindFiles (List, *WildcardPath, 0, 1); for (t_u32 i = 0; i < List.size(); i++) { if (!DeleteDirectory (* (NString (Path) + NUX_BACKSLASH_CHAR + List[i]), true) ) return 0; } List.clear(); return DeleteDirectory (Path, false); }