Click here to Skip to main content
15,896,557 members
Articles / Programming Languages / C++

Change File Extension Context Menu

Rate me:
Please Sign up or sign in to vote.
4.63/5 (15 votes)
7 May 2008CPOL5 min read 83.8K   918   29  
An easy and flexible way to change file extensions.
#include "stdafx.h"
#include "PathSplitter.h"

C_SplitPath::C_SplitPath(LPCTSTR lpszPath){	SplitPathInitialize();if (lpszPath) Split(lpszPath);}

BOOL C_SplitPath::Split(LPCTSTR lpszPath)
{
	SplitPathInitialize();
	if (lpszPath == NULL) return FALSE;
	SplPstatus=_wsplitpath_s(lpszPath, drive0, _MAX_DRIVE, dir0, _MAX_DIR, fname0, _MAX_FNAME, ext0, _MAX_EXT);
	fullpath=lpszPath;
    drive=drive0;
    dir=dir0;
    filename=fname0;
    ext_nodot=ext=ext0;
	ext_nodot.Delete(0,1);

	filetitle+=filename;
	filetitle+=ext;
return ((SplPstatus!=EINVAL) && (SplPstatus!=ERANGE));
}

void C_SplitPath::SplitPathInitialize()
{
    wmemset(drive0, 0, _MAX_DRIVE);//init
    wmemset(dir0, 0, _MAX_DIR);
    wmemset(fname0, 0, _MAX_FNAME);
    wmemset(ext0, 0, _MAX_EXT);
	SplPstatus=NULL;
	fullpath.Empty();
    drive.Empty();
    dir.Empty();
    filename.Empty();
    ext.Empty();
	ext_nodot.Empty();
	filetitle.Empty();
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Croatia Croatia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions