How do I extract drive name from file path?
-
I've got a set of filenames: some are to files which exist, others are to files which do not exist; some are absolute, others are relative; some are on local drives, others on network drives. I'm looking for a way to extract the drive name from a file path, regardless of any of the above factors. Can anyone give me a pointer of where to look for this? Thanx.
-
I've got a set of filenames: some are to files which exist, others are to files which do not exist; some are absolute, others are relative; some are on local drives, others on network drives. I'm looking for a way to extract the drive name from a file path, regardless of any of the above factors. Can anyone give me a pointer of where to look for this? Thanx.
I use something like the following to get the path of an executing application: CString sPath; // get the path where the application is running GetModuleFileName(AfxGetApp()->m_hInstance, sPath.GetBuffer(_MAX_PATH+1),_MAX_PATH); //path+file sPath.ReleaseBuffer(); // releases excess memory sPath = sPath.Left(sPath.ReverseFind('\\')); //keep path ReverseFind finds the zero-based index of the first matching character (from the end). You could use the equivalent of sPath.find and look for the first ":" or ":\" character (without the quotes naturally). Hope this helps. Al ================== The original message was: I've got a set of filenames: some are to files which exist, others are to files which do not exist;
some are absolute, others are relative; some are on local drives, others on network drives.I'm looking for a way to extract the drive name from a file path, regardless of any of the above
factors.Can anyone give me a pointer of where to look for this?
Thanx.
-
I've got a set of filenames: some are to files which exist, others are to files which do not exist; some are absolute, others are relative; some are on local drives, others on network drives. I'm looking for a way to extract the drive name from a file path, regardless of any of the above factors. Can anyone give me a pointer of where to look for this? Thanx.
Have a look at the _splitpath API function... - Chris ================== The original message was: I've got a set of filenames: some are to files which exist, others are to files which do not exist;
some are absolute, others are relative; some are on local drives, others on network drives.I'm looking for a way to extract the drive name from a file path, regardless of any of the above
factors.Can anyone give me a pointer of where to look for this?
Thanx.