473,729 Members | 2,355 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 6912
Bob Gervais <ge********@yah oo.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
2447
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 as a complete url like "http://www....com" . The opendir-function-Error is "Invalid argument". Can anyone help me?
3
4424
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 advance, Jeremy
9
2560
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 snippet: function GetAlbumArt ($path) { if ($handle = opendir ("$path")) { while (false !== ($element = readdir ($handle))) { if (strpos ($element, "AlbumArt") == 0 && strpos ($element, "Large") != 0) { return $element;
2
16097
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, "c:\\Temp\\Directory1") or die "Can't open the directory. $! \n"; while (defined ($filename = readdir(DIR)) ) { open (INPUT, "<c:\\Temp\\directory1\\".$filename) or die "Can't open the
2
3211
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 folder located on my local system. When I try to "openDir" a network drive using the CGI script run through Apache, Apache gives me the error: Can't openDir... However, when I run the CGI script in a DOS window, the command works properly.
4
3329
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 to change. here are some tests I did to see what was wrong: $blah = opendir("blocks"); while ($file = readdir($blah)) {
5
5076
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 worked. When i use this pointer on the array "input", which contains the actual directory, the program cannot read the directory. I already tested if "input" contains the directories at all, but it does. > if ((fp = fopen(fpath, "r")) ==...
7
8467
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 C:\apache\xampp\htdocs\path\to\scriptI have tried the following combinations if(opendir('S:/folder/')) echo 'found'; if(opendir('S:/folder)) echo 'found'; if(opendir('S:\folder\\')) echo 'found'; if(opendir('S:\folder)) echo 'found';
6
8797
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 directory" while my program is working its way thru a tree. This always happens with the same directory (ie. it is not totally random) although there is nothing different or unusual about the ownership or permissions (ie. there actually is such a...
0
9426
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9281
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9200
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9142
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8148
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6022
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4795
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3238
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2163
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.