0
点赞
收藏
分享

微信扫一扫

RenameFile.cpp


// RenameFile.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "RenameFile.h"
//#include "windows.h"
#include "shlwapi.h"
/*
包含头文件 Shlwapi.h
Library Shlwapi.lib
*/
#pragma comment(lib,"Shlwapi.lib")

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/
// The one and only application object

CWinApp theApp;

using namespace std;

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
	int nRetCode = 0;

	// initialize MFC and print and error on failure
	if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
	{
		// TODO: change error code to suit your needs
		cerr << _T("Fatal Error: MFC initialization failed") << endl;
		nRetCode = 1;
	}
	else
	{
		if (argc<3)
		{
			printf("usage: %s filename <file tail to add>\n",argv[0]);
			exit(-1);
		}
		// TODO: code your application's behavior here.
		TCHAR m_OldName[256];
		TCHAR m_NewName[256];
		TCHAR OldFileName[256];//<=m_OldName
		TCHAR OldFileExt[256];

		//MessageBox(NULL,argv[1],argv[0],MB_OK);
		//exit(0);
		strcpy(m_OldName,argv[1]);
		//MessageBox(NULL,m_OldName,argv[0],MB_OK);
		//exit(0);

		LPSTR ext;
		//如"D:\\masm32\\lcd\\lcd.asm",则可返回".asm"的首址
		ext = PathFindExtension(m_OldName);
		strcpy(OldFileExt,ext);
		*ext='\0';
		strcpy(OldFileName,m_OldName);
		//printf(m_OldName);
		//exit(0);
		strcpy(m_NewName,OldFileName);
		strcat(m_NewName,argv[2]);
		strcat(m_NewName,OldFileExt);
		//printf(m_NewName);
		//exit(0);
			try  
			{
				 CFile::Rename(argv[1], m_NewName);  
			 }  
			 catch(CFileException* pEx )  
			 {  
				 TRACE(_T("Rename File %20s Exception, cause =%d\n"), argv[1],  
					 pEx->m_cause);  
				 pEx->Delete();  
			}  
	}

	return nRetCode;
}





桌面\新建文件夹>for %a in (*.h) do RenameFile.ex
e "%a" _offline


举报

相关推荐

0 条评论