473,320 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

opendir and if -d $files problem

Hi,

I am writing a very simple script that should return all
subdirectories on a given path (non recursively, so just first level).

This is the sub that I have for doing this but it gives very strange
results:

sub FindFiles
{
my ($dir) = @_ ;
my @files ;

opendir THISDIR, $dir or die "Error, cannot do opendir on $dir $!"
;
my @allfiles = readdir THISDIR ;
closedir THISDIR ;

foreach my $file (@allfiles)
{
#if (-d $file)
# {
# print $file."\n";
# };
push @files, $file if (-d $file) ;
}

return (@files)
}

When I run this on the same path as the script is located ('.') it
gives me the correct results.
If I give a path along of where to check, it gives me a few of the
subdirs (for example on the C: drive it would give me the TEMP, the
WINDOWS and the RECYCLER directory, but not the PROGRAM FILES or some
other dirs I have.

I am using Perl 5.8 on a Windows XP machine.

Can anyone shed some light on this strange problem?

Thanx,

Bob
Jul 19 '05 #1
1 6868
Bob Gervais <ge********@yahoo.com> wrote:
opendir THISDIR, $dir or die "Error, cannot do opendir on $dir $!";
my @allfiles = readdir THISDIR ;
[ snip ]
When I run this on the same path as the script is located ('.') it
gives me the correct results.


The problem is that readdir() returns filenames, not full paths.

my @subdirs = grep -d, map "$dir/$_", readdir(THISDIR);

[ This group is defunct; please use clp.misc instead. ]

--
Steve
Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Roswitha Schoppe-Jantzen | last post by:
Hi, I want to get all files, that exist in a specific url. I use the opendir and readdir-function - It ist all right, when I use directories like "." or "./test". But I want to use a directory...
3
by: Jeremy Shovan | last post by:
What do I need to change to use the opendir() function when safe mode is in affect?? I have root access to the server and can make any changes neccessary except turn safe mode off Thanks in...
9
by: Andrew DeFaria | last post by:
I'm attempting to put my music collection on the web using PHP and I hit a problem. When I attempt an opendir of a directory that contains a "'" character the opendir fails. Here's the code...
2
by: Andrew | last post by:
I'm trying to learn how to use the opendir() function with perl, and each time I try to run my perl script I keep getting "Permission denied". Here is the script: open (DIR,...
2
by: Alex | last post by:
Greetings all, I'm trying to use the "opendir" command on Win32 in a CGI script. I'm using Apache 2.0.48 for Win32. The "openDir" command works from the CGI script when I try to open a...
4
by: gnah | last post by:
Greetings, I hope my problem is easy to fix, I'm pretty new with php - but I am getting weird results with the opendir() function. It may just be a path problem, but I don't see which variable...
5
by: Markus Pitha | last post by:
Hello, i'm using Gentoo Linux and like to open directories which i got from a text file i read of. I tried to open a directory as i wrote the directory name directly into "opendir()" and it...
7
code green
by: code green | last post by:
I am trying to access files on a different drive but the same server to where the script is running. but I only get the error failed to open dir: Invalid argument in...
6
by: MK | last post by:
I don't use c much but i've done lots of perl, perl/Tk, and shellcode on LINUX. I'm trying to do things with directory trees and i occasionally get back an errno from opendir "No such file or...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.