- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- How to found out if I'm reading a file/link/direct...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
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
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- 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
тАО10-05-2005 10:05 PM
тАО10-05-2005 10:05 PM
I open the dir with opendir, read it with readdir and I get the name of the entries.
How can I understand if they are links or directory or no-link files?
Can stat or lstat help me? I cannot understand how. Please help.
Roy
......
dir = opendir("/tmp")
lsdir=readdir(ifdir);
while ((lsdir = readdir(dir)) != NULL)
{
// how to know if a lsdir->d_name entry is a
// file, link or a directory?
}
closedir(ifdir);
..............
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-05-2005 10:11 PM
тАО10-05-2005 10:11 PM
Re: How to found out if I'm reading a file/link/directory using stat
/* directory entry for this file */
It gives file type. You can know the type of file.
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-05-2005 10:57 PM
тАО10-05-2005 10:57 PM
SolutionThen use S_ISDIR(), S_ISREG() or S_ISLNK() to determine if the file is a directory, regular file (not device file) or symbolic link.
e.g.
struct stat stat_info;
int rc;
rc = lstat(yourfile, &stat_info);
if (rc != 0)
{
// stat error
}
if (S_ISDIR(stat_info.st_mode))
{
// it's a directory
}
else if (S_ISLNK(stat_info.st_mode))
{
// it's a symbolic link
}
else if (S_ISREG(stat_info.st_mode))
{
// it's a regular file
}
else
{
// it's something else - FIFO, device file etc
}
- Tags:
- lstat
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-05-2005 11:43 PM
тАО10-05-2005 11:43 PM
Re: How to found out if I'm reading a file/link/directory using stat
http://www.metalshell.com/view/source/116/
with lstat using st_dev for mapping with macro's like, S_ISLNK()
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-05-2005 11:53 PM
тАО10-05-2005 11:53 PM