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(input)) != NULL) { /* opendir cannot open the directory, stored in "input" */ while ((dirzeiger=readdir(dir)) != NULL) printf("%s\n", (*dirzeiger).d_name); } closedir(dir); } fclose(fp);
Any ideas? 5 5038
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(input)) != NULL) {
while ((dirzeiger=readdir(dir)) != NULL)
printf("%s\n", (*dirzeiger).d_name);
}
closedir(dir);
}
fclose(fp);
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(input)) != NULL) { while ((dirzeiger=readdir(dir)) != NULL) printf("%s\n", (*dirzeiger).d_name); } closedir(dir); } fclose(fp);
--
Al Bowers
Tampa, Fl USA
mailto: xa******@myrapidsys.com (remove the x to send email) http://www.geocities.com/abowers822/
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,pathlength,fp))
{
if((s = strchr(input,'\n')) != NULL) *s = '\0';
if(dir = opendir( .....etc........
......... fgets(input, pathlength, fp); if ((dir=opendir(input)) != NULL) { while ((dirzeiger=readdir(dir)) != NULL) printf("%s\n", (*dirzeiger).d_name); } closedir(dir); } fclose(fp);
--
Al Bowers
Tampa, Fl USA
mailto: xa******@myrapidsys.com (remove the x to send email) http://www.geocities.com/abowers822/
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(input)) != NULL) { while ((dirzeiger=readdir(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.programmer
--
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.
Hello Al,
i adopted your proposal and I even solved another problem too, thanks.
Markus. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
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...
| |