Re: Get Folder from Full File Path
It believe it is basically doing the same thing as using _splitpath.
You can use CString instead of static buffers.
Releasing the buffer cuts off anything extra as I understand it.
void CFileOp::ParseFileName(CString& strFileName)
{
//------------------------------------------------------------------------
//Parse String for Name, Extension, Directory, Drive
//------------------------------------------------------------------------
_splitpath( strFileName.GetBuffer(MAX_PATH),
m_strDrive.GetBuffer(MAX_PATH), m_strDirectory.GetBuffer(MAX_PATH),
m_strFileName.GetBuffer(MAX_PATH), m_strExtension.GetBuffer(MAX_PATH) );
strFileName.ReleaseBuffer();
m_strDrive.ReleaseBuffer();
m_strFileName.ReleaseBuffer();
m_strExtension.ReleaseBuffer();
//------------------------------------------------------------------------
// Save Variables
//------------------------------------------------------------------------
m_strFileNameAndExtension = m_strFileName + m_strExtension;
m_strDriveAndDirectory = m_strDrive + m_strDirectory;
}
You can also preintialize the buffer size or do it on the fly.
m_strDrive.GetBufferSetLength(MAX_PATH);
CString cs = Path;
::PathAddBackslash(cs.GetBuffer(_MAX_PATH));
cs.ReleaseBuffer(-1);