//////////////////////////////////////////////////////////////////////
// XSplitPath.h : interface for the CSplitPath class.
// (c) 1999, Kevin Lussier
//
// Modified by Hans Dietrich
//////////////////////////////////////////////////////////////////////
#ifndef XSPLITPATH_H
#define XSPLITPATH_H
// Example usage
///CSplitPath sp( "C:\\Temp\\Foo.txt" );
// cout << "Drive: " << sp.GetDrive()
// cout << "Directory: " << sp.GetDirectory();
// cout << "File Name: " << sp.GetFileName();
// cout << "Extension: " << sp.GetExtension();
class CSplitPath
{
// Construction
public:
CSplitPath(LPCTSTR lpszPath)
{
// initialize our objects
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));
memset(computername, 0, sizeof(computername));
memset(sharename, 0, sizeof(sharename));
Split(lpszPath);
}
// Operations
BOOL Split(LPCTSTR lpszPath)
{
// if we weren't given a path, fail
if (lpszPath == NULL || lpszPath[0] == _T('\0'))
return FALSE;
// copy the path
_tcsncpy(path_buffer, lpszPath, sizeof(path_buffer)/sizeof(TCHAR) - 1);
// split the given path
_tsplitpath(path_buffer, drive, dir, fname, ext);
if (IsUNC())
{
// Get the computername
_tcsncpy(computername, _tcsstr(dir, _T("\\\\"))+2, sizeof(computername)/sizeof(TCHAR)-1);
_tcsnset(_tcsstr(computername, _T("\\")), 0, 1);
// Strip the computername from the directory
_tcsncpy(dir, _tcsstr(dir, _T("\\\\"))+2, sizeof(dir)/sizeof(TCHAR)-1);
_tcsncpy(dir, _tcsstr(dir, _T("\\")), sizeof(dir)/sizeof(TCHAR)-1);
// Get the share name
_tcsncpy(sharename,_tcsstr(dir, _T("\\"))+1, sizeof(sharename)/sizeof(TCHAR)-1);
_tcsnset(_tcsstr(sharename, _T("\\")), 0, 1);
// Strip the share name from the directory
_tcsncpy(dir, _tcsstr(dir, _T("\\"))+1, sizeof(dir)/sizeof(TCHAR)-1);
_tcsncpy(dir, _tcsstr(dir, _T("\\")), sizeof(dir)/sizeof(TCHAR)-1);
}
return TRUE;
}
CString GetPath(void) { return path_buffer; }
CString GetDrive(void) { return drive; }
CString GetDirectory(void) { return dir; }
CString GetFileName(void) { return fname; }
CString GetExtension(void) { return ext; }
CString GetComputerName(void) { return computername; }
CString GetShare(void) { return sharename; }
BOOL IsUNC(void) { return (_tcsncmp(path_buffer,_T("\\\\"), 2) == 0); }
// Attributes
protected:
TCHAR path_buffer[_MAX_PATH];
TCHAR drive[_MAX_DRIVE];
TCHAR dir[_MAX_DIR];
TCHAR fname[_MAX_FNAME];
TCHAR ext[_MAX_EXT];
TCHAR computername[_MAX_FNAME];
TCHAR sharename[_MAX_FNAME];
};
#endif