HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- printig files in a directory
Operating System - Linux
1827331
Members
6286
Online
109963
Solutions
Forums
Categories
Company
Local Language
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2006 10:49 PM
09-10-2006 10:49 PM
Hi all,
I am using C to read and print files in a directory but i do not want to print the directories within it. I am using readdir(), is there anyway to do this?
Thanks
Henry
I am using C to read and print files in a directory but i do not want to print the directories within it. I am using readdir(), is there anyway to do this?
Thanks
Henry
Solved! Go to Solution.
- Tags:
- readdir
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2006 11:33 PM
09-10-2006 11:33 PM
Re: printig files in a directory
Hi Henry,
You have to check every "dirent entry" with
stat(2) / fstat(2) against its st_mode.
rgds
HGH
You have to check every "dirent entry" with
stat(2) / fstat(2) against its st_mode
rgds
HGH
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2006 11:36 PM
09-10-2006 11:36 PM
Re: printig files in a directory
is C a prerequisite? Why not the easy way: perl or sh
# perl -MFile::Find -le'find(sub{-d and return;print$File::Find::name},@ARGV)' $HOME, /tmp
Enjoy, Have FUN! H.Merijn
# perl -MFile::Find -le'find(sub{-d and return;print$File::Find::name},@ARGV)' $HOME, /tmp
Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2006 02:58 AM
09-11-2006 02:58 AM
Solution
Henry,
after some modifcations:
#include
#include
#include
#include
main()
{
DIR *dirp;
struct dirent *dp;
struct stat buf;
printf("\tFiles:\n");
dirp = opendir(".");
while (dp = readdir(dirp)) {
if (stat(dp->d_name,&buf) == 0)
if(buf.st_mode & S_IFREG) printf("%s\n", dp->d_name);
}
return closedir(dirp);
}
after some modifcations:
#include
#include
#include
#include
main()
{
DIR *dirp;
struct dirent *dp;
struct stat buf;
printf("\tFiles:\n");
dirp = opendir(".");
while (dp = readdir(dirp)) {
if (stat(dp->d_name,&buf) == 0)
if(buf.st_mode & S_IFREG) printf("%s\n", dp->d_name);
}
return closedir(dirp);
}
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Support
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP