473,406 Members | 2,847 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,406 software developers and data experts.

readdir() and S_ISDIR(stat.st_mode) question (OT ?)

I'm not sure if this is POSIX or not ... and indeed if POSIX
is OT here or not, but if the subject made sense to you ....

I have a very simple program here, but it seems to be returning
a "true" value to the query S_ISDIR() even when the directory
entry is not a directory.

#include <stdio.h>
#include <dirent.h>
#include <sys/stat.h>
#include <errno.h>

int main(int argc, char *argv[]) {
DIR *dir;
struct dirent *entry;
struct stat eStat;
char *root;
int i;

root = argv[1];

while((entry = readdir(dir)) != NULL) {
lstat(entry->d_name, &eStat);
if(S_ISDIR(eStat.st_mode))
printf("found directory %s\n", entry->d_name);
else
printf("not a dir\n");
}
return 0;
}
sample output:
found directory .
found directory ..
found directory NCURSES-Programming-HOWTO-html.tar.gz
found directory ncurses_programs
found directory ncurses.html

Nov 14 '05 #1
2 11142
On Thu, 04 Mar 2004 05:08:53 GMT,
electric sheep <el******@null.invalid> wrote:
I'm not sure if this is POSIX or not ... and indeed if POSIX
is OT here or not, but if the subject made sense to you ....


Yes, it is a POSIX question, and it is offtopic here.

comp.unix.programmer is the place where they discuss POSIX.

Martien
--
|
Martien Verbruggen | Think of the average person. Approximately
Trading Post Australia | half of the people out there are dumber.
|
Nov 14 '05 #2
On 04 Mar 2004 05:28:37 GMT,
Martien Verbruggen <mg**@tradingpost.com.au> wrote:

On Thu, 04 Mar 2004 05:08:53 GMT,
electric sheep <el******@null.invalid> wrote:
I'm not sure if this is POSIX or not ... and indeed if POSIX
is OT here or not, but if the subject made sense to you ....


Yes, it is a POSIX question, and it is offtopic here.

comp.unix.programmer is the place where they discuss POSIX.

Regardless of that, it is still a good idea to check possible errors
also from non-ANSI-C functions.
Villy
Nov 14 '05 #3

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

Similar topics

1
by: Ken Tucker | last post by:
Help! I'm recursing through 10,000 directories where some have as few as 5 files and others have 100's. I'm then performing a few things based on the modify date of the file. Needless to say,...
10
by: David Farning | last post by:
I am new to c and not yet sure of the boundary between c and it's implementations. So please redirect me if this should be asked elsewhere. I am working on a function to determine if a directory...
5
by: ulyses | last post by:
Hi i have got quite strange problem. I wrote programme which shows all runnign processes. This info is get from /proc dir. When a dir that is process dir is found stat file is read and pid, name...
3
by: David Bear | last post by:
I'm trying to use os.chmod and am refered to the stat module. Is there are explanation of: * S_ISUID * S_ISGID * S_ENFMT * S_ISVTX * S_IREAD * S_IWRITE * S_IEXEC
9
by: smoothoperator12 | last post by:
Hi all, I have spent hours trying to figure out where I have went wrong with my code for my recursive function to list all the files in a directory, and all of the files in all of its...
1
by: georgewa | last post by:
Greetings all, great forum, this is my first post. Recently trying to write a script that is designed to move files based on timestamps. I am fairly new to Perl, so please bare with me. I have...
2
by: asit | last post by:
why this program shows ambiguous behavior ?? import os import stat import time #import types file_name=raw_input("Enter file name : ") print file_name, "information" st=os.stat(file_name)
2
by: Rolf =?UTF-8?B?S3LDvGdlcg==?= | last post by:
Hi I´m about learning C/C++ and after covering the language basics I´m now heading for my first "real" application where I need to use the POSIX stuff for directory operations. Here´s my...
4
by: Laharl | last post by:
My Operating Systems professor has assigned homework that basically boils down to implementing ls -lra, but with a different output format. In other words, list the files and subdirectories (and a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
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...
0
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,...
0
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...
0
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...
0
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,...
0
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...

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.