473,796 Members | 2,544 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_aktualisier enClick(object sender, System.EventArg s e)
{
// clear listview
lv_fileliste.Cl ear();

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

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

May 30 '06 #1
4 5035
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(), FindExInfoStand ard, &FindFileDat a,
FindExSearchNam eMatch, 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.cF ileName,
}
while( FindNextFile( hFind, &FindFileDat a ) );

FindClose(hFind );


--
Regards, Ron AF Greve

http://moonlit.xs4all.nl

"Peter Pippinger" <pe************ *@gmx.de> wrote in message
news:11******** **************@ y43g2000cwc.goo glegroups.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_aktualisier enClick(object sender, System.EventArg s e)
{
// clear listview
lv_fileliste.Cl ear();

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

// Insert files in listview
foreach ( FileInfo fi in fileInfo )
{
lv_fileliste.It ems.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.Filesyste m 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_itera tor 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
1745
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 where I could modify tha pages. But when I open the .aspx pages with Visual studio.net, then I just see the HTML code & no design view of the page. How should I edit the page when in Visual Studio I cant see the design view. Just in case...
1
2613
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? 'This code was originally written by Ken Getz. 'It is not to be altered or distributed, 'except as part of an application. 'You are free to use it in any application, 'provided the copyright notice is left unchanged. '
9
3883
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
2813
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 src="employee.aspx.cs". It looks like my bin/employee.dll file is not being used. Instead, my employee.aspx.cs file is being used.
3
3489
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. -Regards Arun
4
1863
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 debugger (Insight debugger, which is a GUI front-end to GDB version 5.3). In fact, when I try to view the header file, all I see is assembly language. There is another header file in the same directory, which does not have any inline member...
1
1300
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 XML files. The issue I have is that the debugger creates temporary folders and copies the DLL to it when using the "Test View" tool. My XML files are copied to the BIN directory of the library so the debugger can't see the XML files to read them. ...
5
16933
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 development computer, but when i take the files to another computer and install them using the deployment project files, when i go to execute it on the different computer, it gives the error "You are not authorized to view this page. HTTP Error 403 -...
11
7127
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 source files in "D:\Sadiq\Projects\Onlineres". The folder structure is as follows. 1) D:\Sadiq\Projects\Onlineres: This folder is having the context.xml, web.xml, build.xml and build.properties files.
0
9528
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10456
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10230
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10174
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10012
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5442
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5575
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2926
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.