473,378 Members | 1,470 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,378 software developers and data experts.

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 2225
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.whinlatter.uklinux.net>, ${roger}
@invalid.whinlatter.uklinux.net.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
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...
1
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....
1
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...
3
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,...
3
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...
1
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...
11
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...
0
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...
8
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.