LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-01-2005, 05:42 PM   #1
TruongAn
Member
 
Registered: Dec 2004
Location: Vietnam (Việt Nam)
Distribution: Gentoo (desktop), Arch linux (laptop)
Posts: 728

Rep: Reputation: 33
How can you distinct between link and file when using readdir


Hello everyone

I am writing a program which will read a directory
and call rm to delete any file it encourage but spare
the directory, And it will dive into subdirectory until
all file is deleted

But when I use readdir I see that it can open symbolic
and file also. Because this program is dangerous, I don't
want it to follow the link to another folder, It may earase
all my hardisk in this way.

Do you know any way to recognize a link when anything
you have is a name??
 
Old 09-01-2005, 05:49 PM   #2
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
You can stat() the file/dir and then use S_ISDIR() or whatever to find out what it is. Those macros are all explained in the man page for stat.
 
Old 09-01-2005, 06:25 PM   #3
primo
Member
 
Registered: Jun 2005
Posts: 542

Rep: Reputation: 34
You'd want to use lstat(2) instead because it doesn't follow symlinks.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to use DISTINCT in Query for all items nephish Linux - Networking 18 07-29-2005 03:37 AM
Two distinct issues -- sound & rxvt Poetics Linux - Software 6 05-11-2005 04:31 AM
about readdir r_213 Programming 1 01-16-2005 11:26 PM
Regarding readdir r_213 Linux - Networking 2 01-15-2005 07:56 AM
after readdir how can I open all the files jupe Programming 1 07-13-2004 09:00 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:05 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration