0
0

hello i want to display the file name like mySong.mp3 and not C:\mymusic\MP3\mysong.mp3

Is there a function to do that???

Thank’s

  • You must to post comments
0
0

Try the following. Windows does have a StripPath function but including shlwapi.lib just for one function is excessive. Note this is not perfect and there is not error checking (i.e. return tmp+1; is dangerous if tmp is at the end of path) but it’s a start.

Also do not free the return value from strip_path as this is only a pointer into your original string.

[code:2ztlzp7w]#include <string.h>

include <stdio.h>

// the const means the return value is not yours to free. sorta.
const char *strip_path( char *path )
{
char *tmp = strrchr( path, (int)’\’ );
if ( tmp == NULL ) return path;
return tmp + 1; // dangerous ... left as an exercise :)
}

int main( void )
{
char *path = "C:\mymusic\MP3\mysong.mp3 ";
printf("File is called %s\n", strip_path(path));
}[/code:2ztlzp7w]

Hope this helps.

  • You must to post comments
0
0

I use this easy function:

[code:20ovvzrs]void extrName(char *filename) {
int pos = strlen(filename) – 1;
while (pos–) {
if (filename[pos] == ‘\’) {
strcpy(filename, filename + pos + 1);
break;
}
}
}[/code:20ovvzrs]

  • You must to post comments
0
0

THX 😛

  • You must to post comments
Showing 3 results
Your Answer

Please first to submit.