Gossamer Forum
Home : General : Perl Programming :

Attributes of an entry in a Directory

Quote Reply
Attributes of an entry in a Directory
readdir() returns a string which is either a directory name or a file name. How can I detect the type of entry?
Douglas Maughan
Winchester, UK
Quote Reply
Re: [silvermist] Attributes of an entry in a Directory In reply to
Not sure....PHP offers a cool function called is_dir(), but I don't know about Perl. The way I would do it is;


if ($file =~ /\./) {
# got a . in it, so assuming its a file...
} else {
# here we assume its a directory...
}

Hope that helps Smile

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [silvermist] Attributes of an entry in a Directory In reply to
I think -d would do the trick here:

Code:
my $is_dir = -d $filename;

if ($is_dir) {
# It's a dir
}
else {
# It's not a dir
}

Regards,
Charlie
Quote Reply
Re: [Andy] Attributes of an entry in a Directory In reply to
You can't say "if it has got a dot in the name it is a file" ......that is very unreliable.

Most operating systems have "dotless" files and likewise directories with dots in the names.

You need to use the following:

http://gossamer-threads.com/...e%20writable;#200798

stat() gives further details:

http://www.perldoc.com/...1/pod/func/stat.html
Quote Reply
Re: [Paul] Attributes of an entry in a Directory In reply to
AS I said Paul..it was an idea...not a very good one, but a starting point!

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Attributes of an entry in a Directory In reply to
That's right and I was pointing out a more reliable solution as Charlie did (except Charlie beat me) Tongue.