Home > Software engineering >  GetFileName () get the name of the file, how to separate the extension?
GetFileName () get the name of the file, how to separate the extension?

Time:09-24

Use vc + + 6,
With the GetFileName () get the name of the file, how to separate the extension?

CodePudding user response:

GetFileName. Mid (GetFileName. Find ('. ') + 1)

CodePudding user response:

Thank you so much!

reference 1st floor vcttyys response:
GetFileName. The mids (GetFileName. Find ('. ') + 1)


I use like this:
Cstrings cs;
Cs=File. GetFileName ();
AfxMessageBox (File. GetFileName ());
Cs. Mid (CST. Find ('. ') + 1);
AfxMessageBox (cs);

Look at this time of cs is still the file name

CodePudding user response:

refer to the second floor dontium response:
thank you!

Quote: refer to 1st floor vcttyys response:

GetFileName. Mid (GetFileName. Find ('. ') + 1)


I use like this:
Cstrings cs;
Cs=File. GetFileName ();
AfxMessageBox (File. GetFileName ());
Cs. Mid (CST. Find ('. ') + 1);
AfxMessageBox (cs);

Look at this time of cs is still the file name

This way is not rigorous, may sometimes is wrong, because some file name is likely to have more than one '. 'or'. '

CodePudding user response:

Using cstrings write their own can see: http://jiadexinqing0317.blog.163.com/blog/static/1339597902012217112846389/

Direct use of library functions to see: http://blog.sina.com.cn/s/blog_a3e571160101gn5n.html

CodePudding user response:

reference paschen reply: 3/f
Quote: refer to the second floor dontium response:
thank you!

Quote: refer to 1st floor vcttyys response:

GetFileName. Mid (GetFileName. Find ('. ') + 1)


I use like this:
Cstrings cs;
Cs=File. GetFileName ();
AfxMessageBox (File. GetFileName ());
Cs. Mid (CST. Find ('. ') + 1);
AfxMessageBox (cs);

Look at this time of cs is still the file name

This way is not rigorous, may sometimes is wrong, because some file name is likely to have more than one '. 'or'. '

The moderator's right!

CodePudding user response:

_splitpath, _wsplitpath
Break a path name into components.

Void _splitpath (const char * path, char * drive, char * dir, char * fname, char * ext);

Void _wsplitpath (const would * path, would drive, would be * dir, would be * fname, would be * ext);

CodePudding user response:

Positive solution, upstairs _tsplitpath function is useful, write their own judging algorithm, may have to judge whether there is hidden extension system,

CodePudding user response:

PathFindExtension

CodePudding user response:

refer to the second floor dontium response:
thank you!

Quote: refer to 1st floor vcttyys response:

GetFileName. Mid (GetFileName. Find ('. ') + 1)


I use like this:
Cstrings cs;
Cs=File. GetFileName ();
AfxMessageBox (File. GetFileName ());
cs. Mid (CST) Find ('. ') + 1);
AfxMessageBox (cs);

CodePudding user response:

Be careful in the file. The file,

CodePudding user response:

Recommended by the first post, 4/f, easy to understand

CodePudding user response:

reference paschen reply: 3/f
Quote: refer to the second floor dontium response:
thank you!

Quote: refer to 1st floor vcttyys response:

GetFileName. Mid (GetFileName. Find ('. ') + 1)


I use like this:
Cstrings cs;
Cs=File. GetFileName ();
AfxMessageBox (File. GetFileName ());
Cs. Mid ( CST. Find (') + 1);
AfxMessageBox (cs);

Look at this time of cs is still the file name

This way is not rigorous, may sometimes is wrong, because some file name is likely to have more than one '. 'or'. '


So if you have more than one point could not find, if there is no extension, will go wrong?

CodePudding user response:

Use strtok or strtok_s cstrings string segmentation

CodePudding user response:

Cstrings cs=File. GetFileName ();
Cstrings ext=: : PathFindExtension (cs) (LPCTSTR);
PathFindExtension
Shell Path Handling Functions provides
  • Related