Getting the filename in c++

the _splitpath function is used to extract the drive,directory,filename and extension from a filepath. Here’s a snippet of how to use it:

#include <stdlib.h>

int main(int argc,char **argv)
{
char drive[_MAX_DRIVE];
char dir[_MAX_DIR];
char fname[_MAX_FNAME];
char ext[_MAX_EXT];

for(int i=0;i<argc;i++)
{
_splitpath(argv[i],drive,dir,fname,ext);
printf("drive: %s\n",drive);
printf("dir: %s\n",dir);
printf("fname: %s\n",fname);
printf("ext: %s\n",ext);
}

system("pause");
return 0;
}

_splitpath

Advertisements

One response to “Getting the filename in c++

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s