vc2008递归建立一个目录工程
来源:互联网 发布:linux iso镜像百度云 编辑:程序博客网 时间:2024/06/03 19:42
扫描指定目录并递归其子目录的所有文件,生成一个xml的VCMakeTool类型的工程文件.
usage:buildvcproj dir destfilename
example:buildvcproj c://abc abc.xml
#include "stdafx.h"
#include <windows.h>
FILE *g_pFile=NULL;
const char *g_packsDir=NULL;
int g_packsDirLen=0;
void Build(const char *packsDir, const char *subdir)
{
WIN32_FIND_DATAA FindFileData;
HANDLE hFind = INVALID_HANDLE_VALUE;
char DirSpec[MAX_PATH]; // directory specification
DWORD dwError;
strcpy(DirSpec,packsDir);
int rlen = strlen(DirSpec);
if(DirSpec[rlen -1]=='\\')
{
DirSpec[rlen-1]='0';
}
if(subdir&&subdir[0]!=0)
{
strcat(DirSpec,"\\");
strcat(DirSpec,subdir);
}
int saveLen = strlen(DirSpec);
strcat(DirSpec,"\\*");
hFind = FindFirstFileA(DirSpec, &FindFileData);
DirSpec[saveLen]='\0';
if (hFind != INVALID_HANDLE_VALUE)
{
do
{
if(FindFileData.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY )
{
if(FindFileData.cFileName[0]!='.'
&& strstr(FindFileData.cFileName,"objchk")==NULL
&& strstr(FindFileData.cFileName,"objfre")==NULL
)
{
fprintf(g_pFile," <Filter "
"\nName=\"%s\""
"\nFilter=\"cpp;c;h;cc;cxx;def;odl;idl;hpj;bat;asm;asmx\""
"\n>\n",FindFileData.cFileName
);
Build(DirSpec,FindFileData.cFileName);
fprintf(g_pFile,"%s\n","\n </Filter>\n");
}
}
else
{
int len =strlen(FindFileData.cFileName);
if(len<4 || strcmpi(FindFileData.cFileName+len-4,".obj")!=0)
{
fprintf(g_pFile,
"\n<File"
"\nRelativePath=\".%s\\%s\""
"\n></File>\n",
DirSpec+g_packsDirLen,FindFileData.cFileName);
}
}
}
while (FindNextFileA(hFind, &FindFileData) != 0) ;
dwError = GetLastError();
FindClose(hFind);
}
}
int main(int argc, char* argv[])
{
if(argc<3)
{
printf("usage:\nbuildvcproj dir destfilename\n"
"example:\n"
"buildvcproj c:\\abc abc.xml\n");
return 0;
}
g_pFile=fopen(argv[2],"w");
if(g_pFile)
{
fprintf(g_pFile,"%s",
"<?xml version=\"1.0\" encoding=\"gb2312\"?>"
"\n<VisualStudioProject"
"\n ProjectType=\"Visual C++\""
"\n Version=\"9.00\""
"\n Name=\"win2ksrc\""
"\n ProjectGUID=\"{8B8C6959-68F6-4182-8EA9-87C1E30EBE9E}\""
"\n Keyword=\"MakeFileProj\""
"\n TargetFrameworkVersion=\"196613\""
"\n >"
"\n <Platforms>"
"\n <Platform"
"\n />"
"\n </Platforms>"
"\n <ToolFiles>"
"\n </ToolFiles>"
"\n <Configurations>"
"\n <Configuration"
"\n Name=\"Debug|Win32\""
"\n OutputDirectory=\"$(ConfigurationName)\""
"\n IntermediateDirectory=\"$(ConfigurationName)\""
"\n ConfigurationType=\"0\""
"\n >"
"\n <Tool"
"\n Name=\"VCNMakeTool\""
"\n BuildCommandLine=\"\""
"\n ReBuildCommandLine=\"\""
"\n CleanCommandLine=\"\""
"\n Output=\"win2ksrc.exe\""
"\n PreprocessorDefinitions=\"WIN32;_DEBUG\""
"\n IncludeSearchPath=\"\""
"\n ForcedIncludes=\"\""
"\n AssemblySearchPath=\"\""
"\n ForcedUsingAssemblies=\"\""
"\n CompileAsManaged=\"\""
"\n />"
"\n </Configuration>"
"\n <Configuration"
"\n Name=\"Release|Win32\""
"\n OutputDirectory=\"$(ConfigurationName)\""
"\n IntermediateDirectory=\"$(ConfigurationName)\""
"\n ConfigurationType=\"0\""
"\n >"
"\n <Tool"
"\n Name=\"VCNMakeTool\""
"\n BuildCommandLine=\"\""
"\n ReBuildCommandLine=\"\""
"\n CleanCommandLine=\"\""
"\n Output=\"win2ksrc.exe\""
"\n PreprocessorDefinitions=\"WIN32;NDEBUG\""
"\n IncludeSearchPath=\"\""
"\n ForcedIncludes=\"\""
"\n AssemblySearchPath=\"\""
"\n ForcedUsingAssemblies=\"\""
"\n CompileAsManaged=\"\""
"\n />"
"\n </Configuration>"
"\n </Configurations>"
"\n <References>"
"\n </References>"
"\n <Files>"
"\n "
);
g_packsDir=argv[1];
g_packsDirLen= strlen(g_packsDir);
Build(g_packsDir,"");
fprintf(g_pFile,"%s",
"\n </Files>"
"\n <Globals>"
"\n </Globals>"
"\n</VisualStudioProject>"
);
fclose(g_pFile);
}
else
{
printf("Can not open file %s\n",argv[2]);
}
return 0;
}
- vc2008递归建立一个目录工程
- 建立工程目录
- 建立一个C6000simulator工程
- 递归方法建立树形目录
- 递归删除一个目录
- vc2008工程转vc2005
- mkdir命令(建立一个目录)
- Android教程(三)-- 建立工程与工程目录介绍
- VC2008正确建立PDB文件
- VC2008/2005工程自动生成器
- 用批处理编译VC2008工程
- 命令行下编译VC2008工程
- 用批处理编译VC2008工程
- 用递归做了一个文件夹建立
- 第一章 建立一个WPF/E工程
- 建立一个简单的android涂鸦工程
- 使用vc++建立一个utility工程
- Cocos2d入门 <一>建立一个新工程
- Hibernate映射解析——七种映射关系
- 安装cmake 和opencv并在Qt中使用opencv(linux-pc环境)
- delphi rtti
- Sqlserver 如何修改替换text,ntext类型字段
- Qt 系统找不到指定的路径
- vc2008递归建立一个目录工程
- Struts2中的OGNL详解
- 二维码生成与解析代码实现
- SURF:加速鲁棒特征算法
- xp 配置DCOM
- GNU-ld链接脚本浅析
- android学习:intent/filter
- 写自己的makefile,让别人去说吧!
- curl_errno错误号大全中文版