473,729 Members | 2,355 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

opendir doesn't work..

Hello,
i'm using Gentoo Linux and like to open directories which i got from a
text file i read of. I tried to open a directory as i wrote the
directory name directly into "opendir()" and it worked. When i use this
pointer on the array "input", which contains the actual directory, the
program cannot read the directory.
I already tested if "input" contains the directories at all, but it does.
if ((fp = fopen(fpath, "r")) == NULL) {
fprintf(stderr, "Couldn't open config file");
exit(1);
}
while (!feof (fp) ) {
fgets(input, pathlength, fp);
if ((dir=opendir(i nput)) != NULL) { /* opendir cannot open the directory, stored in "input" */
while ((dirzeiger=rea ddir(dir)) != NULL)
printf("%s\n", (*dirzeiger).d_ name);
}
closedir(dir);
}
fclose(fp);


Any ideas?
Nov 14 '05 #1
5 5076
Now i hope the code looks fine...

if ((fp = fopen(fpath, "r")) == NULL) {
fprintf(stderr, "Couldn't open config file");
exit(1);
}
while (!feof (fp) ) {
fgets(input, pathlength, fp);
if ((dir=opendir(i nput)) != NULL) {
while ((dirzeiger=rea ddir(dir)) != NULL)
printf("%s\n", (*dirzeiger).d_ name);
}
closedir(dir);
}
fclose(fp);
Nov 14 '05 #2


Markus Pitha wrote:
Now i hope the code looks fine...

if ((fp = fopen(fpath, "r")) == NULL) {
fprintf(stderr, "Couldn't open config file");
exit(1);
}
while (!feof (fp) ) {
There is a faq question on this. Read:
http://www.eskimo.com/~scs/C-faq/q12.2.html

Instead of using the function feof simply make
the while loop:
while(NULL != fgets(input, pathlength, fp))
{
if(dir=opendir( input)) ...etc...
....

fgets(input, pathlength, fp);
if ((dir=opendir(i nput)) != NULL) {
while ((dirzeiger=rea ddir(dir)) != NULL)
printf("%s\n", (*dirzeiger).d_ name);
}
closedir(dir);
}
fclose(fp);


--
Al Bowers
Tampa, Fl USA
mailto: xa******@myrapi dsys.com (remove the x to send email)
http://www.geocities.com/abowers822/

Nov 14 '05 #3


Al Bowers wrote:


Markus Pitha wrote:
Now i hope the code looks fine...

if ((fp = fopen(fpath, "r")) == NULL) {
fprintf(stderr, "Couldn't open config file");
exit(1);
}
while (!feof (fp) ) {

There is a faq question on this. Read:
http://www.eskimo.com/~scs/C-faq/q12.2.html

Instead of using the function feof simply make
the while loop:
while(NULL != fgets(input, pathlength, fp))
{
if(dir=opendir( input)) ...etc...
....


I forgot to mention that function fgets will read the
newline char in most situations. For example, if you
have a line in the file with a directory name of
"windows", function fgets will reading into the
input buffer "windows\n" . Depending on the definiton
of function, this might fail. I suggest you remove
the newline char before calling function opendir.

#include <stdio.h>
#include <string.h>

char *s;
while(NULL != fgets(input,pat hlength,fp))
{
if((s = strchr(input,'\ n')) != NULL) *s = '\0';
if(dir = opendir( .....etc....... .
.........

fgets(input, pathlength, fp);
if ((dir=opendir(i nput)) != NULL) {
while ((dirzeiger=rea ddir(dir)) != NULL)
printf("%s\n", (*dirzeiger).d_ name);
}
closedir(dir);
}
fclose(fp);



--
Al Bowers
Tampa, Fl USA
mailto: xa******@myrapi dsys.com (remove the x to send email)
http://www.geocities.com/abowers822/

Nov 14 '05 #4
On Sun, 12 Sep 2004 12:47:55 GMT
Markus Pitha <ma****@acid4u. com> wrote:
Now i hope the code looks fine...

if ((fp = fopen(fpath, "r")) == NULL) {
fprintf(stderr, "Couldn't open config file");
exit(1);
}
while (!feof (fp) ) {
fgets(input, pathlength, fp);
if ((dir=opendir(i nput)) != NULL) {
while ((dirzeiger=rea ddir(dir)) != NULL)
printf("%s\n", (*dirzeiger).d_ name);
}
closedir(dir);
}
fclose(fp);


The C language as defined by the ISO/ANSI standards does not support
reading directories. You need to ask in either a Linux programming group
(since your previous post said you use Gentoo) or a unix programming
group such as comp.unix.progr ammer
--
Flash Gordon
Sometimes I think shooting would be far too good for some people.
Although my email address says spam, it is real and I read it.
Nov 14 '05 #5
Hello Al,
i adopted your proposal and I even solved another problem too, thanks.

Markus.
Nov 14 '05 #6

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

Similar topics

0
2447
by: Roswitha Schoppe-Jantzen | last post by:
Hi, I want to get all files, that exist in a specific url. I use the opendir and readdir-function - It ist all right, when I use directories like "." or "./test". But I want to use a directory as a complete url like "http://www....com" . The opendir-function-Error is "Invalid argument". Can anyone help me?
3
4424
by: Jeremy Shovan | last post by:
What do I need to change to use the opendir() function when safe mode is in affect?? I have root access to the server and can make any changes neccessary except turn safe mode off Thanks in advance, Jeremy
9
2560
by: Andrew DeFaria | last post by:
I'm attempting to put my music collection on the web using PHP and I hit a problem. When I attempt an opendir of a directory that contains a "'" character the opendir fails. Here's the code snippet: function GetAlbumArt ($path) { if ($handle = opendir ("$path")) { while (false !== ($element = readdir ($handle))) { if (strpos ($element, "AlbumArt") == 0 && strpos ($element, "Large") != 0) { return $element;
2
16097
by: Andrew | last post by:
I'm trying to learn how to use the opendir() function with perl, and each time I try to run my perl script I keep getting "Permission denied". Here is the script: open (DIR, "c:\\Temp\\Directory1") or die "Can't open the directory. $! \n"; while (defined ($filename = readdir(DIR)) ) { open (INPUT, "<c:\\Temp\\directory1\\".$filename) or die "Can't open the
2
3211
by: Alex | last post by:
Greetings all, I'm trying to use the "opendir" command on Win32 in a CGI script. I'm using Apache 2.0.48 for Win32. The "openDir" command works from the CGI script when I try to open a folder located on my local system. When I try to "openDir" a network drive using the CGI script run through Apache, Apache gives me the error: Can't openDir... However, when I run the CGI script in a DOS window, the command works properly.
4
3329
by: gnah | last post by:
Greetings, I hope my problem is easy to fix, I'm pretty new with php - but I am getting weird results with the opendir() function. It may just be a path problem, but I don't see which variable to change. here are some tests I did to see what was wrong: $blah = opendir("blocks"); while ($file = readdir($blah)) {
6
1819
by: dmcglynn | last post by:
Hello all.. I have a strange issue. I am trying to do an opendir via a UNC path, from my windows server to another windows machine. As long as my remote machine is on a physically wired connection, it works great. However, if my remote machine is on a wireless network, I get the following error: Warning: opendir(\\10.51.50.79\plc$): failed to open dir: Invalid
7
8467
code green
by: code green | last post by:
I am trying to access files on a different drive but the same server to where the script is running. but I only get the error failed to open dir: Invalid argument in C:\apache\xampp\htdocs\path\to\scriptI have tried the following combinations if(opendir('S:/folder/')) echo 'found'; if(opendir('S:/folder)) echo 'found'; if(opendir('S:\folder\\')) echo 'found'; if(opendir('S:\folder)) echo 'found';
6
8797
by: MK | last post by:
I don't use c much but i've done lots of perl, perl/Tk, and shellcode on LINUX. I'm trying to do things with directory trees and i occasionally get back an errno from opendir "No such file or directory" while my program is working its way thru a tree. This always happens with the same directory (ie. it is not totally random) although there is nothing different or unusual about the ownership or permissions (ie. there actually is such a...
0
8917
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
8761
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,...
1
9200
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
9142
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
8148
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6722
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...
1
3238
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2680
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2163
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.