For Programmers: Free Programming Magazines  


Home > Archive > VC Language > May 2006 > How do get the files in a directory?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author How do get the files in a directory?
Peter Pippinger

2006-05-30, 8:08 am

Hello NG,

I have written some code which worked fine under c#. But i don=B4t know,

how this shoud work in c++. I have tryed much things, but i can=B4t find

out how to use DirectoryInfo and FileInfo under c++.


Thanks for any hints!
Peter


Here is the c# code:


//------------------------------------------------------
//-- View *.prn Files in Directory
//------------------------------------------------------
void Btn_aktualisierenClick(object sender, System.EventArgs e)
{
// clear listview
lv_fileliste.Clear();


DirectoryInfo dir =3D new DirectoryInfo("c:\\");
FileInfo[] fileInfo =3D dir.GetFiles("*.prn");


// Insert files in listview
foreach ( FileInfo fi in fileInfo )
{
lv_fileliste.Items.Add(fi.Name.ToString(),0);
}=20
}

Arman Sahakyan

2006-05-30, 8:08 am

Hi,

See _findfirst, _findnext



--
======
Arman


"Peter Pippinger" wrote:

> Hello NG,
>
> I have written some code which worked fine under c#. But i don´t know,
>
> how this shoud work in c++. I have tryed much things, but i can´t find
>
> out how to use DirectoryInfo and FileInfo under c++.
>
>
> Thanks for any hints!
> Peter
>
>
> Here is the c# code:
>
>
> //------------------------------------------------------
> //-- View *.prn Files in Directory
> //------------------------------------------------------
> void Btn_aktualisierenClick(object sender, System.EventArgs e)
> {
> // clear listview
> lv_fileliste.Clear();
>
>
> DirectoryInfo dir = new DirectoryInfo("c:\\");
> FileInfo[] fileInfo = dir.GetFiles("*.prn");
>
>
> // Insert files in listview
> foreach ( FileInfo fi in fileInfo )
> {
> lv_fileliste.Items.Add(fi.Name.ToString(),0);
> }
> }
>
>

Alex Blekhman

2006-05-30, 8:08 am

Peter Pippinger wrote:
> Hello NG,
>
> I have written some code which worked fine under c#. But
> i don´t know, how this shoud work in c++. I have tryed
> much things, but i can´t find out how to use
> DirectoryInfo and FileInfo under c++.


Under C++ you don't have standard way to do what you want.
There is non-portable _findfirst, _findnext, _findclose
family of functions in CRT. If you programming within some
framework (like MFC, for example), then usually you will
have a class, which helps to emumerate files and folders. In
MFC it's CFileFind class.

The closest thing to DirectoryInfo is scripting component
FileSystemObject. If you don't mind using COM, then you can
do something like that:

#import "progid:Scripting.FileSystemObject"
....
using namespace Scripting;
....
IFileSystem3Ptr ptrFso(__uuidof(FileSystemObject));
IDrivePtr ptrDrive = ptrFso->Drives->Item[L"C:"];


David D

2006-05-30, 8:08 am

Have a look at "Boost Filesystem Library"
http://www.boost.org/libs/filesystem/doc/index.htm

/David

Peter Pippinger wrote:
> Hello NG,
>
> I have written some code which worked fine under c#. But i don´t know,
>
> how this shoud work in c++. I have tryed much things, but i can´t find
>
> out how to use DirectoryInfo and FileInfo under c++.
>
>
> Thanks for any hints!
> Peter
>
>
> Here is the c# code:
>
>
> //------------------------------------------------------
> //-- View *.prn Files in Directory
> //------------------------------------------------------
> void Btn_aktualisierenClick(object sender, System.EventArgs e)
> {
> // clear listview
> lv_fileliste.Clear();
>
>
> DirectoryInfo dir = new DirectoryInfo("c:\\");
> FileInfo[] fileInfo = dir.GetFiles("*.prn");
>
>
> // Insert files in listview
> foreach ( FileInfo fi in fileInfo )
> {
> lv_fileliste.Items.Add(fi.Name.ToString(),0);
> }
> }
>

Mark Randall

2006-05-30, 8:08 am

FindFirstFile API.

--
- Mark Randall
http://www.temporal-solutions.co.uk

"We're Systems and Networks..."
"It's our job to know..."

"Peter Pippinger" <peter.pippinger@gmx.de> wrote in message
news:1148985196.660448.115380@j55g2000cwa.googlegroups.com...
Hello NG,

I have written some code which worked fine under c#. But i don´t know,

how this shoud work in c++. I have tryed much things, but i can´t find

out how to use DirectoryInfo and FileInfo under c++.


Thanks for any hints!
Peter


Here is the c# code:


//------------------------------------------------------
//-- View *.prn Files in Directory
//------------------------------------------------------
void Btn_aktualisierenClick(object sender, System.EventArgs e)
{
// clear listview
lv_fileliste.Clear();


DirectoryInfo dir = new DirectoryInfo("c:\\");
FileInfo[] fileInfo = dir.GetFiles("*.prn");


// Insert files in listview
foreach ( FileInfo fi in fileInfo )
{
lv_fileliste.Items.Add(fi.Name.ToString(),0);
}
}


Marcus Heege

2006-05-30, 7:15 pm

Hi Peter,

in addition to the suggestions mentioned already, you may consider using the
/clr flag. In this case you can use the same types from the base class
library that you used in C#.

Marcus


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com