Reputation: 2763
I need to get the name of a file from its full path, in vc++. How can I get this? I need only the file name. Can I use Split method to get this? If not how can I get the file name from the full path of the file?
Upvotes: 0
Views: 2048
Reputation: 11
Upvotes: 0
Reputation: 10747
String^ fileName = "C:\\mydir\\myfile.ext";
String^ path = "C:\\mydir\\";
String^ result;
result = Path::GetFileName( fileName );
Console::WriteLine( "GetFileName('{0}') returns '{1}'", fileName, result );
Upvotes: 1
Reputation: 108975
Find the last \
or /
1 using one of the standard library string/char *
search methods. Then extract the following text. Remember to special case where the /
or \
is the last character.
1 The Windows API, for most purposes2 supports both.
1 The exception is when using long paths starting \\?\
to break 260 character limit on paths.
Upvotes: 0