如何将DirectoryInfo句柄转换为用户定义的类? [英] How can I convert a DirectoryInfo handle to a user-defined class?
问题描述
我正在用Visual c ++进行一个名为文件搜寻器"的项目.它将简单地索引文件中指定目录的所有文件.用户可以通过扩展名,名称等在此c ++文件中搜索特定文件.
现在,我想将所有文件名和目录放入我创建的类的对象中.我发现此代码很有帮助:
I am working on a project named "file crawler" in visual c++. It will simply index all the files of a specified directory in a file. The user can search this c++ file for a particular file through extension, name etc.
Right now, I want to get all the file names and directories into an object of my created class. I found this code helpful:
using namespace System;
using namespace System::IO;
int main()
{
// Make a reference to a directory.
DirectoryInfo^ di = gcnew DirectoryInfo( "d:\\" );
// Get a reference to each file in that directory.
array<FileInfo^>^fiArr = di->GetFiles();
// Display the names of the files.
Collections::IEnumerator^ myEnum = fiArr->GetEnumerator();
while ( myEnum->MoveNext() )
{
FileInfo^ fri = safe_cast<FileInfo^>(myEnum->Current);
Console::WriteLine( fri->Name );
}
}
问题在于此代码使用文件信息句柄,并且我不知道如何将所有这些数据传输到将成为目录类(我的类)中指针的对象.
我的课是这样的:
The problem is that this code uses the file info handle and I don''t know how to transfer all this data to an object that will be a pointer in a directory class (my class).
My class is like this:
class directories
{
//data members
ffile *file; //file is my class
ddirectory *sdirectory //ddirectory will hold the names of subdirectories
string path;
};
我还需要以下说明:
I also need the explanation of:
Collections::IEnumerator^ myEnum = fiArr->GetEnumerator();
我正在毕业的第二年.请给我一些建议.我有20天的时间来完成此项目.
I am doing second year of graduation. Please suggest some ideas to me. I have 20 days to complete this project.
推荐答案
我相信您可能会发现以下有趣的内容:
http://www.boost.org/doc/libs/1_46_0/libs/filesystem/v3/doc/tutorial.html [ ^ ]-它甚至可以在其他操作系统上运行
您也可以使用
http://www.boost.org/doc/libs/1_46_0/libs/regex/doc/html/index.html [ ^ ]可以促进非常高级的搜索条件.
上面的内容比使用C ++/CLI更像是一种真正的" C ++方法,但是,如果您想使用C ++/CLI,则以下文章应该可以帮助您解决C ++/CLI中的问题:
C ++ :. NET Framework编程最强大的语言 [ ^ ]
十二个面包师:在移植Visual C ++ .NET之前应该了解的十三件事程序 [ ^ ]
使用C ++/CLI编写高效且可靠的代码的最佳做法 [ ^ ]
也有产品文档 [布鲁斯·埃克尔(Bruce Eckel)在C ++第二版中的思考 [
I believe you may find this interesting:
http://www.boost.org/doc/libs/1_46_0/libs/filesystem/v3/doc/tutorial.html[^] - it will even work on other os''es
You can also use
http://www.boost.org/doc/libs/1_46_0/libs/regex/doc/html/index.html[^] to facilitate quite advanced search criteria.
The above is more of a "real" C++ approach than using C++/CLI, but if you want to use C++/CLI the following articles should help you to solve your problem in C++/CLI:
C++: The Most Powerful Language for .NET Framework Programming[^]
A Baker''s Dozen: Thirteen Things You Should Know Before Porting Your Visual C++ .NET Programs[^]
Best Practices for Writing Efficient and Reliable Code with C++/CLI[^]
There is also the product documentation[^]
If you are new to C++, take a look at:
Thinking in C++ 2nd Edition by Bruce Eckel[^]
The links will allow you to solve your problem, but you''re the one who is going to create your solution.
Good luck :)
Regards
Espen Harlinn
这篇关于如何将DirectoryInfo句柄转换为用户定义的类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!