473,587 Members | 2,463 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Opening directories


Hi

I've tried to find out if and how I can open
directories in standard C++, the same way I
can open files. To my great suprise, I haven't
managed to find out how this is done!

I'm using MS VC++ 6.0, so I know I could
use some Win specific classes, but I was
hoping to write portable code, and hence
I'm looking for some way of "opening" a
directory that's not platform or file system
dependant, since this code eventually will
be running on both Windows and Linux PCs.

So does such functions exist?

What I want to accomplish, is to be able to
make a very crude "file browser", that can
take some "root directory", and read its
subdirectories into a vector or something.
Then I can print a simple menu with "hit 1
to enter mydir", and so on. And when you've
entered the desired directory, you can display
files of some predefined extention, and run
them by hitting the appropriate menu item.

What it's all for? Feeding scripts to a test
bench. I'm writing a testbench for a hardware
design.

Any inputs would be greatly appreaciated.

Cheers
-Fred
Jul 22 '05 #1
7 2257
Fred H wrote:

Hi

I've tried to find out if and how I can open
directories in standard C++, the same way I
can open files. To my great suprise, I haven't
managed to find out how this is done!


What is surprising you?
C++ doesn't have standard facilities to do that
and BTW. who has told you that a directory behaves
like a file?

--
Karl Heinz Buchegger
kb******@gascad .at
Jul 22 '05 #2
Fred H wrote
Hi

I've tried to find out if and how I can open directories in
standard C++, the same way I can open files. To my great
suprise, I haven't managed to find out how this is done!

I'm using MS VC++ 6.0, so I know I could use some Win
specific classes, but I was hoping to write portable code,
and hence I'm looking for some way of "opening" a directory
that's not platform or file system dependant, since this
code eventually will be running on both Windows and Linux
PCs.

So does such functions exist?

What I want to accomplish, is to be able to make a very
crude "file browser", that can take some "root directory",
and read its subdirectories into a vector or something.
Then I can print a simple menu with "hit 1 to enter mydir",
and so on. And when you've entered the desired directory,
you can display files of some predefined extention, and run
them by hitting the appropriate menu item.

What it's all for? Feeding scripts to a test bench. I'm
writing a testbench for a hardware design.

Any inputs would be greatly appreaciated.

Cheers -Fred


The standard is silent on directories, so there is no way to
do what you want in Standard C++. However, the work of
porting a filesystem interface has already been done:

http://www.boost.org/libs/filesystem/doc/index.htm
Jul 22 '05 #3
Fred H <se****@nospam. com> writes:
I've tried to find out if and how I can open
directories in standard C++, the same way I
can open files. To my great suprise, I haven't
managed to find out how this is done!

I'm using MS VC++ 6.0, so I know I could
use some Win specific classes, but I was
hoping to write portable code, and hence
I'm looking for some way of "opening" a
directory that's not platform or file system
dependant, since this code eventually will
be running on both Windows and Linux PCs.

So does such functions exist?


The portable way would be to use these POSIX functions: opendir(3),
closedir(3), readdir(3) and rewinddir(3).

Unfortunately, Microsoft OSes are about the only common ones not to
support POSIX. There are third party POSIX libraries for Windows
however (Cygwin and MinGW come to mind).
I've written a C++ class for this: mail me for details (remove the ${}
and invalids), or Google this group (I posted it a few weeks back).
--
Roger Leigh

Printing on GNU/Linux? http://gimp-print.sourceforge.net/
GPG Public Key: 0x25BFB848. Please sign and encrypt your mail.
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 22 '05 #4
In article <87************ @wrynose.whinla tter.uklinux.ne t>, ${roger}
@invalid.whinla tter.uklinux.ne t.invalid says...

[ ... ]
The portable way would be to use these POSIX functions: opendir(3),
closedir(3), readdir(3) and rewinddir(3).
POSIX is "portable" in name, but in little else. ECMA 234 provides
functions for reading directories that I'm quite certain are portable to
a LOT more machines than POSIX (a large majority of machines that
support these POSIX functions also support the ECMA 234 functions, and
I'd bet there are far more ECMA 234/non-POSIX machines than there are
POSIX/non-ECMA 234 machines).
Unfortunately, Microsoft OSes are about the only common ones not to
support POSIX. There are third party POSIX libraries for Windows
however (Cygwin and MinGW come to mind).


Current Microsoft OSes (e.g. Windows NT, Windows 2000, Windows XP,
Windows 2003) all have a POSIX subsystem that, the last time I checked,
actually had a somewhat MORE accurate implementation of POSIX than many
of the systems more programmers are more likely to think of as
supporting POSIX (e.g. Linux, *BSD).

In all these cases, there are some fairly large areas where nearly all
the common systems are clearly deficient in implementing the full
current POSIX standard (e.g. none of the above appears to meet the
requirements for the real-time portion of the POSIX standard). At the
same time, opendir, closedir, readdir and rewinddir all work just as
well on Windows as they do on Linux, *BSD, etc.

Of course, you have to use the POSIX subsystem to do this -- these are
not part of Win32. You should not, however, mistake Win32 for being the
entire OS, by any means.

--
Later,
Jerry.

The universe is a figment of its own imagination.
Jul 22 '05 #5

What is surprising you?
C++ doesn't have standard facilities to do that
Well, that was what surprised me. As long as one can
manipulate files in standard C++, one really ought to
be able to manipulate directories too. Hence, when I
found no such standard way, I was surprised. After all,
it's a pretty common task.
and BTW. who has told you that a directory behaves
like a file?


Well, I know there are lots of ways to implement file
systems and physically store directory information to
disk, but in the sense that directories are chunks of
bytes on disk, the similarities with files are significant ;)
Jul 22 '05 #6

The standard is silent on directories, so there is no way to do what you
want in Standard C++. However, the work of porting a filesystem
interface has already been done:

http://www.boost.org/libs/filesystem/doc/index.htm


Thanks. This seems to be exactly what I need. I hope... :-)
Jul 22 '05 #7
Of course, you have to use the POSIX subsystem to do this -- these are
not part of Win32.
Thanks. I've tried to find out how I to use it, but haven't
managed to find out yet. Any input would be greatly appreaciated.
You should not, however, mistake Win32 for being the
entire OS, by any means.


I'm not sure I understand what you mean by this. Feel free to
enlighten me :)
Jul 22 '05 #8

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

Similar topics

1
1497
by: SD Keane | last post by:
I have windows server 2003 installed at my end. IIS 6.0 got installed then. Then I installed visual studio .net and got a warning that exchange server 2000 does not work with IIS 6. But I installed VS.NET. Now I found that my ASPX pages were not opening. I found a post on net asking user to change a few values. I carried all steps, then also only one virtual directory is working. If I create say 2 more virtual directories......then none...
1
4390
by: Alfons | last post by:
Hello, I have build a program that can do file transferring between a Windows XP computer and a DOS computer via a serial port. The Windows program I have build in C++ with Visual Studio 6.0. The DOS program I made in Turbo C++ 3.0. At this moment I am in a test phase of sending files and directories. The code I am using in DOS to open a file for writing looks like this (forgive me the typos, since I only have my source code at work...
1
2162
by: ramsin.savra | last post by:
Hi, I'm using same code for opening a TIFF file in VC++ works just fine but under linux it says unable to open the tiff file! Any comment on this? if (argc < 2) { cout << "Not enough parameter" << endl;
3
4287
by: Mehmet Gunacti | last post by:
Hello, on our homepage, when pressing an anchor tag, a special sized popup window opens via javascript. but it opens very slowly. on other web pages, there are also javascript-opened windows, but they load very very fast, within 2-3 seconds. i tried several things such as :
3
1969
by: Paras Sharma | last post by:
Hi all, We are facing this big problem. Scenario is as follows. We have one single solution (say EIS) under which there are 25 projects. All the files are saved at a central location under Visual Sorce Safe on a seprate machine. For a new person who is trying to setup this solution file on his / her local machine follows the following step. 1. "Set working folder" for the EIS folder from VSS on to his local machine
1
1659
by: Westbrook, Christopher L (WESTBCL04) | last post by:
I am having some trouble, and I can't figure out why. I'm trying to use the simple keylogger project from source forge, and then create a web interface to open the resulting files, so people from the outside can see the keys logged on a server. I've got the keylogger script working fine, and I have a script that reads and displays all the directories and files of the log directory, but when I select the link of the file it doesn't open. ...
11
3584
by: aldrin | last post by:
I'm trying to run this code under windows xp sp2 using codeblocks v1.0 compiler with great difficulty.There is no problem with running this under KDevelop in linux. Any help would be greatly appreciated. Enter an interesting string. Too many cooks spoil the broth Error opening C:\myfile.txt for writing. Program termnated. This application has requested the Runtime to terminate it in an unusual way.
0
1333
by: SergioRykov | last post by:
during opening VS2005 VS creates directories such as system.pdb, and also creates pingme.txt. Solution contains only simple C# application. How can I change folder location for them? And second moment: in *.csproj I've changed some properties: <PropertyGroup> <top_srcdir>..</top_srcdir> <OutputPath>$(top_srcdir)\out\$(Platform)\$(Configuration)</OutputPath> ...
8
1458
by: perlhelp | last post by:
Hi everyone, I am relatively new to perl. I am trying to write a script that can access directories that have variable numbers appended to the end. For example, I have 4 directories that all have an incremental number (1->4) and then an incremental number at the end (x->x+4) that is variable. Besides that the names are identical. For example: this_is_identical_1_more_identical_15 this_is_identical_2_more_identical_16...
0
7924
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8219
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
8349
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
7978
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
8221
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...
1
5722
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3845
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...
1
1455
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1192
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.