/**********************************************************************
* Copyright (C) 2007 - All Rights Reserved
*
* File: SplitPath.h
* Description: 进行文件路径字符串分割
*
* Authors: yanglinbo,
* Revisions: See bottom of file.
*
***********************************************************************/
#ifndef __SplitPath_H__
#define __SplitPath_H__
class CSplitPath
{
public:
CSplitPath( LPCTSTR lpszPath = NULL )
{
memset( path_buffer, 0, sizeof( path_buffer ) );
memset( drive, 0, sizeof( drive ) );
memset( dir, 0, sizeof( dir ) );
memset( fname, 0, sizeof( fname ) );
memset( ext, 0, sizeof( ext ) );
if ( lpszPath ) Split( lpszPath );
}
// 进行分割
BOOL Split(LPCTSTR lpszPath )
{
if ( lpszPath == NULL ) return FALSE;
_tcsncpy( path_buffer, lpszPath, sizeof( path_buffer ) - 1 );
_tsplitpath( path_buffer, drive, dir, fname, ext );
return TRUE;
}
// 获取全路径 :"C:\\Temp\\Foo.txt"
CString GetFullPath( void ) { return path_buffer; }
// 获取驱动器盘符 :"C:"
CString GetDrive( void ) { return drive; }
// 获取除去盘符文件名的路径 :"\\Temp\\"
CString GetDirectory( void ) { return dir; }
// 获取文件名称除去扩展名 : "Foo"
CString GetFileName( void ) { return fname; }
// 获取扩展名 :".txt"
CString GetExtension( void ) { return ext; }
// 获取全文件名称 : "Foo.txt"
CString GetFullFileName( void ) { return this->GetFileName() + this->GetExtension(); }
protected:
TCHAR path_buffer[_MAX_PATH];
TCHAR drive[_MAX_DRIVE];
TCHAR dir[_MAX_DIR];
TCHAR fname[_MAX_FNAME];
TCHAR ext[_MAX_EXT];
};
#endif