How to read Directory Names 
Author Message
 How to read Directory Names

I (beginner) am trying to read names of the directories under
another directory. I've been looking for documentations, but all
i found is "readdir()", which seems to read only file names!
Here's my code (Win32):

############################################

opendir(DIR,"\\images\\");


if (open(DIR_ONE,"\\images\\$Directory\\info.txt")) {
$DIR_Title = ;
close(DIR_ONE);

Quote:
}

else {
$DIR_Title = $Directory;

Quote:
}

print $Gallery";
print "$Gallery_Title\n";

Quote:
}

############################################

Please Help!!

* Sent from RemarQ http://www.*-*-*.com/ The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!



Wed, 18 Jun 1902 08:00:00 GMT  
 How to read Directory Names

Quote:

>I (beginner) am trying to read names of the directories under
>another directory. I've been looking for documentations, but all
>i found is "readdir()", which seems to read only file names!

If you're only looking for directories directly under DIR, then readdir is
indeed what you want.  If you want to go arbitrarily deep into the directory
tree, you should take a look at the File::Find module.

You can use the -d file test operator to check whether you have a directory:

while($file = readdir(DIR)) {
  if(-d "$dir/$file") {
    process subdirectory...
  }

Quote:
}

--t

--



Wed, 18 Jun 1902 08:00:00 GMT  
 How to read Directory Names
On Sun, 27 Feb 2000 20:29:51 -0800 mimi

Quote:
> I (beginner) am trying to read names of the directories under
> another directory. I've been looking for documentations, but all
> i found is "readdir()", which seems to read only file names!
> Here's my code (Win32):

Make sure every program you write starts out like this:

#!/path/to/perl -w
use strict;

If you are writing CGI do this, instead:

#!/path/to/perl -wT
use strict;

Quote:
> opendir(DIR,"\\images\\");

- Double quotes are for variable interpolation.  
- Use forward slashes.  Doesn't matter if you are on Win32.
- ALWAYS check the return value for errors.

   my $dir = '/images';

   opendir( DIR, $dir )
      or die "Failed to open directory '/images': Error='$!'";

Quote:
> #rewinddir(GALLERY_DIR);




while ( my $file = readdir( DIR ) ) {
    print $file," is a directory!\n" if -d "$dir/$file";

Quote:
}

--

pls note the one line sig, not counting this one.


Wed, 18 Jun 1902 08:00:00 GMT  
 How to read Directory Names
He says he is using Win32.
There is no #! in win32 perl so he doesn't need the #!/path/to/perl -w
Quote:
>Make sure every program you write starts out like this:

>#!/path/to/perl -w
>use strict;



Wed, 18 Jun 1902 08:00:00 GMT  
 How to read Directory Names

Quote:

> He says he is using Win32.
> There is no #! in win32 perl so he doesn't need the #!/path/to/perl -w

But even under Win32 the line has the desired effect: enable warnings.

Erik



Wed, 18 Jun 1902 08:00:00 GMT  
 How to read Directory Names

[ Jeopardectomy performed ]


Quote:
>>Make sure every program you write starts out like this:

>>#!/path/to/perl -w
>>use strict;
>He says he is using Win32.
>There is no #! in win32 perl so he doesn't need the #!/path/to/perl -w

Yes he does.

Everybody needs warnings enabled (at least during development).

I understand that the method above does indeed turn on
warnings on Win32 systems (did you try it?).

--
    Tad McClellan                          SGML Consulting

    Fort Worth, Texas



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Limitation when reading names in directory ?

2. Reading file names but not directories

3. Q: How to read all the file name in a directory

4. Reading a %hash of Directory names

5. newbie : looking for a script that reads all the file names in the directory

6. Reading directories, entering directories, chaning file permissions...

7. Directory Names with Perl for NT

8. Newbie warning: How to place current directory name into variables

9. Identifying names of newest files in directory

10. Obtaining login name used to access .htaccess protected directory

11. WANTED: perl script for gopher .cap directory to .names file

12. Resolving directory name

 

 
Powered by phpBB® Forum Software