VC++创建目录

这几天暑期集训带队,每天会将各个队的进度报告和自己的带队笔记放到相应的目录下。我习惯每天的记录单独存放,比如今天会创建个名为”090708”的目录,明天会创建一个名为“090709”的。而在这个目录下,会将各队的信息单独存放,就是要创建三个目录:“MFC队”,“ASP队”,“改键工具”。本来想手工一个个建的,后来想不如编程实现。查了些资料,用VC++实现了。
参照DirectoryInfo类的例子写成的。其实用到的托管到底是怎么回事我现在也没搞清楚。忙完实验室了回头看看吧。
创建控制台程序,选择空项目。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
using namespace System;
using namespace System::IO;
 
 
int main()
{
	DirectoryInfo^ di;
	String^ fatherDir;
	String^ fatherDir_prefix = gcnew String ("I:9暑期集训mstc&&cc监督进度907");
	for(int i=8;i<=20;i++){
		fatherDir = gcnew String ("");
		if(i<10){
			fatherDir = fatherDir_prefix + "0"+ i;
		}else{
			fatherDir = fatherDir_prefix + i;
		}
 
		di= gcnew DirectoryInfo(fatherDir);
 
		if(di->Exists == false)
			di->Create();
 
		// Create three subdirectory in the directory just created.
		di->CreateSubdirectory( "MFC队" );
		di->CreateSubdirectory( "ASP队" );
		di->CreateSubdirectory( "改键工具" );
	}
}

在编译时,会遇到编译错误。需要设置下:

1. 项目属性—配置属性—常规—字符集,选择多字节字符集。VC2005默认是Unicode。
2. 提示错误error C2871: “System”: 具有该名称的命名空间不存在时,是因为程序是托管代码,在项目中选择公共语言运行库支持/clr就好了。设置路径就在设置字符集的下面一栏。
3. 提示错误error LNK2001: unresolved external symbol _WinMain@16。参照:vc中error LNK2001:unresolved external symbol _WinMain@16的解决方法

2 Comments are ready?

  1. felix021 said on: 2009年07月9日 00:27

    托管代码的简单解释:http://baike.baidu.com/view/159896.htm
    其实哪需要那么麻烦, 一个system函数就行了。

    我喜欢在表示路径名的时候使用/作为分隔符,在Win/Linux下都OK。

    [回复]

    boluor 回复  于   

    恩.还有很多方法的.只是在看MSDN的时候,看到例子很简单,就顺着写完了^.^

    [回复]

  2. sandy said on: 2009年07月9日 13:25

    这种应用,一个vbs十几行代码就搞定了,只需开个记事本敲两下,哪用得着劳神开VS……

    [回复]

    felix021 回复  于   

    似乎用bat更快。。

    [回复]

Post a Comment

Your email is never published nor shared. Required fields are marked *

*

*

click to changeSecurity Code