473,396 Members | 1,970 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How do i view files of a directory?

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);
}
}

May 30 '06 #1
4 5016
Standard C++ doesn't have support for reading directory listings.

If you are on Windows, see functions in platform SDK for Files and
Directories. Or you may use MFC class CFileFind.

-shailesh

May 30 '06 #2
shailesh wrote:
Standard C++ doesn't have support for reading directory listings.

If you are on Windows, see functions in platform SDK for Files and
Directories. Or you may use MFC class CFileFind.
Or look into the Boost file system library (not just for windows.)

-shailesh


Ben
May 30 '06 #3
Hi,

A few threads ago I posted some notes and in another some code. This is
basically what you need
WIN32_FIND_DATA FindFileData;
HANDLE hFind;
string Wild = Dirname;

if( !Wild.empty() )
{
if( *Wild.rbegin() != '\\' ) Wild += '\\';

}
string Dir = Wild;
Wild += "*.*";

hFind = FindFirstFileEx( Wild.c_str(), FindExInfoStandard, &FindFileData,
FindExSearchNameMatch, NULL, 0 );

if (hFind == INVALID_HANDLE_VALUE)
{

stringstream Error;
Error << "Invalid File Handle. GetLastError reports " << GetLastError ()
<< endl;

// NOTE if errorcode is 2 it isn't really an error ('no such file or
directory')

throw CInfoException( Error.str() );
}
else
{
do
{
//NOTE: Filename = FindFileData.cFileName,
}
while( FindNextFile( hFind, &FindFileData ) );

FindClose(hFind);


--
Regards, Ron AF Greve

http://moonlit.xs4all.nl

"Peter Pippinger" <pe*************@gmx.de> wrote in message
news:11**********************@y43g2000cwc.googlegr oups.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);
}
}
May 30 '06 #4
Peter Pippinger wrote:
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 DirectoryInfo dir = new DirectoryInfo("c:\\");
FileInfo[] fileInfo = dir.GetFiles("*.prn");


This used to be off-topic for this group. But Boost.Filesystem is proposed
to the standard. It gives you fairly simple syntax, and portability.

Get it from http://boost.org/, read about it at http://boost.org/libs/filesystem/
The class directory_iterator is hiding in section Operations

Reference:
http://boost.org/libs/filesystem/doc...ctory_iterator
Example:
http://boost.org/libs/filesystem/doc/index.htm#tutorial

If you're not used to such things, the most daunting part may be
that you need to compile the library (also off-topic here, and documented).

hth,
homsan
May 30 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: pmud | last post by:
Hi I have a website (ASP.NET project using C# ) which is already put up on the server. I need to make some modification to some web pages.So the project files were copied to the a different server...
1
by: Wayne | last post by:
I'm using the following code from the Access Web to open a folder. The folder opens in "List" View. Is there an addition that I can make to the code to force the folder to open in "Details" view?...
9
by: sonu | last post by:
I want to develop a application from where we can select files from a tree view Directly like window explor. Please help me
1
by: Jerry Tovar | last post by:
I am using .Net 2003 on a XPPro running IIS. I am unable to view any of my ASPX webforms in a browser unless I modify the .ASPX file and replace Codebehind="employee.aspx.cs" with...
3
by: Arun | last post by:
Hi, I have simple question to ask. How to write multiple Binary files to the Browser using Asp.Net and Visual C#.net I have seen examples where single binary file is written to browser. ...
4
by: Generic Usenet Account | last post by:
In our environment we have several C++ header files that have some inline member function definitions. For some reason, I am unable to step through the source code of those member functions in my...
1
by: SteveT | last post by:
I've written a small library that contains external XML files that will be read by the DLL during program execution. I want to use the "Test View" features of VS2005 to debug the reading of the...
5
by: Tony Girgenti | last post by:
Hello. I developed and tested a web application using VS.NET 2003, VB, .NET Framework 1.1.4322, ASP.NET 1.1.4322 and IIS5.1. It uses a web form. Development testing works fine on my...
11
by: mjahabarsadiq | last post by:
Hi I have created a web application. I am using ant to build the war and deploy in tomcat. The war file is deployed under "TOMCATE_HOME/work/standalone/localhost/onlineres.war". I have my...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.