In many codes, many programmers use the string lookup function in the C library to obtain the file name or extension of a path string. This is a lot of code, and it is also troublesome.
In fact, it can be obtained in a better way in VC. The Code is as follows:
Lptstr szfilename = new tchar [max_path]; getmodulefilename (null, szfilename, max_path); // wchar_t drive [_ max_drive] obtains information such as the drive letter, file name, and extension. wchar_t dir [_ max_dir]; wchar_t fname [_ max_fname]; wchar_t ext [_ max_ext]; errno_t err; err =: _ partition (szfilename, drive, _ max_drive, Dir, _ max_dir, fname, _ max_fname, ext, _ max_ext); // only obtain the path pathremovefilespec (szfilename );
Note: The _ wsplitpath_s function does not change the content in szfilename, but pathremovefilespec does.
Header file:
_ Wsplitpath_s () is in stdlib. h.
The pathremovefilespec () function is in shlwapi. h.