Blog
Developers
Careers
Support
Contact
Gossamer Threads
Solutions
Results
About
Mailing Lists
Resource Centre
Forum
Tools
Home
Who's Online
Tags
Favourites
Login
Forum Search
(
Advanced Search
)
This forum
This category
All forums
for
Home
:
General
:
Perl Programming
:
Attributes of an entry in a Directory
Previous Thread
Next Thread
Print Thread
View Threaded
Oct 11, 2002, 5:00 AM
silvermist
Novice
(6 posts)
Oct 11, 2002, 5:00 AM
Post #1 of 6
Views: 6365
Shortcut
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
Oct 11, 2002, 5:26 AM
Andy
Veteran
/ Moderator
(18441 posts)
Oct 11, 2002, 5:26 AM
Post #2 of 6
Views: 6316
Shortcut
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
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!
Oct 11, 2002, 6:55 AM
Chaz
Enthusiast
(819 posts)
Oct 11, 2002, 6:55 AM
Post #3 of 6
Views: 6244
Shortcut
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
Oct 11, 2002, 6:56 AM
Paul
Veteran
(19537 posts)
Oct 11, 2002, 6:56 AM
Post #4 of 6
Views: 6269
Shortcut
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
Oct 11, 2002, 6:59 AM
Andy
Veteran
/ Moderator
(18441 posts)
Oct 11, 2002, 6:59 AM
Post #5 of 6
Views: 6246
Shortcut
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!
Oct 11, 2002, 7:08 AM
Paul
Veteran
(19537 posts)
Oct 11, 2002, 7:08 AM
Post #6 of 6
Views: 6217
Shortcut
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)
.
Previous Thread
Next Thread
Print Thread
View Threaded