Add CreateDirectories.
Fix, simplify and optimize split().
This commit is contained in:
+34
-23
@@ -109,33 +109,20 @@ CString join( const CString &Deliminator, const CStringArray& Source)
|
|||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void split( const CString &Source, const CString &Deliminator, CStringArray& AddIt, const bool bIgnoreEmpty )
|
void split( const CString &Source, const CString &Deliminator, CStringArray& AddIt, const bool bIgnoreEmpty )
|
||||||
{
|
{
|
||||||
CString newCString;
|
int startpos = 0;
|
||||||
CString tmpCString;
|
|
||||||
CString AddCString;
|
|
||||||
|
|
||||||
int pos1 = 0;
|
|
||||||
int pos = 0;
|
|
||||||
|
|
||||||
newCString = Source;
|
|
||||||
do {
|
do {
|
||||||
pos1 = 0;
|
int pos = Source.Find(Deliminator, startpos);
|
||||||
pos = newCString.Find(Deliminator, pos1);
|
if ( pos == -1 ) pos=Source.GetLength();
|
||||||
if ( pos != -1 ) {
|
|
||||||
CString AddCString = newCString.Left(pos);
|
|
||||||
if( newCString.IsEmpty() && bIgnoreEmpty )
|
|
||||||
; // do nothing
|
|
||||||
else
|
|
||||||
AddIt.Add(AddCString);
|
|
||||||
|
|
||||||
tmpCString = newCString.Mid(pos + Deliminator.GetLength());
|
CString AddCString = Source.Mid(startpos, pos-startpos);
|
||||||
newCString = tmpCString;
|
if( AddCString.IsEmpty() && bIgnoreEmpty )
|
||||||
}
|
; // do nothing
|
||||||
} while ( pos != -1 );
|
else
|
||||||
|
AddIt.Add(AddCString);
|
||||||
|
|
||||||
if( newCString.IsEmpty() && bIgnoreEmpty )
|
startpos=pos+1;
|
||||||
; // do nothing
|
} while ( startpos <= Source.GetLength() );
|
||||||
else
|
|
||||||
AddIt.Add(newCString);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -264,6 +251,30 @@ void splitrelpath( const CString &Path, CString& Dir, CString& FName, CString& E
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* mkdir -p. Doesn't fail if Path already exists and is a directory. */
|
||||||
|
bool CreateDirectories( CString Path )
|
||||||
|
{
|
||||||
|
CStringArray parts;
|
||||||
|
CString curpath;
|
||||||
|
Path.Replace("\\", "/");
|
||||||
|
split(Path, "/", parts);
|
||||||
|
|
||||||
|
for(int i = 0; i < parts.GetSize(); ++i)
|
||||||
|
{
|
||||||
|
curpath += parts[i] + "/";
|
||||||
|
if(CreateDirectory( curpath, NULL ))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if(GetLastError() != ERROR_ALREADY_EXISTS)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
/* Make sure it's a directory. */
|
||||||
|
if( !IsADirectory(curpath) )
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void GetDirListing( CString sPath, CStringArray &AddTo, bool bOnlyDirs, bool bReturnPathToo )
|
void GetDirListing( CString sPath, CStringArray &AddTo, bool bOnlyDirs, bool bReturnPathToo )
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -162,6 +162,7 @@ CString join(
|
|||||||
const CStringArray& Source
|
const CStringArray& Source
|
||||||
);
|
);
|
||||||
|
|
||||||
|
bool CreateDirectories( CString Path );
|
||||||
void GetDirListing( CString sPath, CStringArray &AddTo, bool bOnlyDirs=false, bool bReturnPathToo=false );
|
void GetDirListing( CString sPath, CStringArray &AddTo, bool bOnlyDirs=false, bool bReturnPathToo=false );
|
||||||
bool GetFnmDirListing( const CString &sPath, CStringArray &AddTo, bool bOnlyDirs, bool bReturnPathToo, ... );
|
bool GetFnmDirListing( const CString &sPath, CStringArray &AddTo, bool bOnlyDirs, bool bReturnPathToo, ... );
|
||||||
unsigned int GetHashForString( CString s );
|
unsigned int GetHashForString( CString s );
|
||||||
|
|||||||
Reference in New Issue
Block a user