Update of /cvsroot/smartwin/SmartWin/include/io
In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv25774/include/io
Modified Files:
InDialogClasses.h
Log Message:
Add directory and file functions
Index: InDialogClasses.h
===================================================================
RCS file: /cvsroot/smartwin/SmartWin/include/io/InDialogClasses.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- InDialogClasses.h 30 Nov 2006 00:36:49 -0000 1.6
+++ InDialogClasses.h 10 Dec 2006 22:36:05 -0000 1.7
@@ -95,6 +95,109 @@
itsFilterNo = inFilterNo;
}
+
+ // Static functions
+ //-------------------------------------------------------------
+
+ // return c:\dir\subdir
+ // from c:\dir\subdir\file.ext
+ //
+ static SmartUtil::tstring pathOf( const SmartUtil::tstring & pathFile )
+ {
+ size_t slashDex= pathFile.find_last_of('\\');
+ if ( string::npos == slashDex ) {
+
+ }
+ return pathFile.substr( 0, slashDex );
+ }
+
+ //-------------------------------------------------------------
+
+ // return file.ext
+ // from c:\dir\subdir\file.ext
+ //
+ static SmartUtil::tstring fileOf( const SmartUtil::tstring & pathFile )
+ {
+ size_t slashDex= pathFile.find_last_of('\\');
+ if ( string::npos == slashDex ) {
+
+ }
+ return pathFile.substr( ++slashDex );
+ }
+
+
+ //-------------------------------------------------------------
+
+ // return .ext
+ // from file.ext
+ //
+ static SmartUtil::tstring extensionOf( const SmartUtil::tstring & fileDotExtension )
+ {
+ size_t dotDex= fileDotExtension.find_last_of('.');
+ if ( string::npos == dotDex ) {
+
+ }
+ return fileDotExtension.substr( dotDex );
+ }
+
+
+ //-------------------------------------------------------------
+
+ // return file
+ // from file.ext
+ //
+ static SmartUtil::tstring discardExtensionOf( const SmartUtil::tstring & fileDotExtension )
+ {
+ size_t dotDex= fileDotExtension.find_last_of('.');
+ if ( string::npos == dotDex ) {
+
+ }
+ return fileDotExtension.substr( 0, dotDex );
+ }
+
+ //-------------------------------------------------------------
+
+ /// copy a file from the source file to the destination file
+ //
+ static bool copyFile( const SmartUtil::tstring & source,
+ const SmartUtil::tstring & dest,
+ bool failIfExists = false )
+ {
+ if ( ::CopyFile( source.c_str(), dest.c_str(), failIfExists ? TRUE : FALSE ) ) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ //-------------------------------------------------------------
+
+ static bool deleteFile( const SmartUtil::tstring & filePath )
+ {
+ if ( ::DeleteFile( filePath.c_str() ) ) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ //-------------------------------------------------------------
+
+ static bool setFileAttributes( const SmartUtil::tstring & filePath,
+ DWORD attributes )
+ {
+ if ( ::SetFileAttributes( filePath.c_str(), attributes ) ) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ //-------------------------------------------------------------
+
+
+ // member variables
+
bool itsLoadFile; // True implies use of WidgetLoadFile, false implies WidgetSaveFile.
bool itsRelative;
unsigned itsFilterNo;
@@ -139,6 +242,41 @@
}
+ //
+ //
+ bool dirExists()
+ {
+ DWORD retv= GetFileAttributes( itsDirPath.c_str() );
+ if ( 0xffffffff != retv ) {
+ if ( FILE_ATTRIBUTE_DIRECTORY & retv ) return true;
+ }
+ return false;
+ }
+
+
+ // Create this directory
+ // Returns true if this directory was created
+ //
+ bool createDir()
+ {
+ if ( CreateDirectory( itsDirPath.c_str(), NULL ) ) {
+ return( true );
+ } else {
+ return( false );
+ }
+ }
+
+ bool removeDirectory()
+ {
+ if ( RemoveDirectory( itsDirPath.c_str() ) ) {
+ return( true );
+ } else {
+ return( false );
+ }
+ }
+
+
+
// IN: A new directory for this class instance.
// OUT: returns a vector of the parent and subdirectories of inDirPath
//
@@ -230,7 +368,8 @@
}
-
+ // Generate the vector of subdirectories
+ //
vector< SmartUtil::tstring > genSubDirectories()
{
vector< SmartUtil::tstring > subdirs; // Return value
@@ -265,8 +404,9 @@
}
- //
+ // Generate a vector of files that match a wildcard.
// fullpath, if true, returns files as c:\dir\subdir\file.ext
+ // if false,returns files as file.ext
//
vector< SmartUtil::tstring > genFiles( bool fullPath= true, SmartUtil::tstring ext = _T("*") )
{
@@ -304,6 +444,41 @@
}
+ // Static functions
+
+
+ //-------------------------------------------------------------
+
+ static SmartUtil::tstring currentDir()
+ {
+ TCHAR cur_dir[MAX_PATH];
+ GetCurrentDirectory( MAX_PATH, cur_dir );
+
+ return SmartUtil::tstring( cur_dir );
+ }
+
+ //-------------------------------------------------------------
+
+ static bool setCurrentDirectory( const SmartUtil::tstring & pathFile )
+ {
+ if ( SetCurrentDirectory( pathFile.c_str() ) )
+ return true;
+ else
+ return false;
+ }
+
+
+ //-------------------------------------------------------------
+
+ static SmartUtil::tstring getWindowsDirectory()
+ {
+ TCHAR winDir[MAX_PATH];
+ if ( GetWindowsDirectory( winDir, MAX_PATH ) ) {
+ return SmartUtil::tstring( winDir );
+ }
+
+ return SmartUtil::tstring(); // Empty if err.
+ }
|