#!/perl -w use strict; ##Code is tested on winxp with perl 5.8## my $path = "c:\\"; my @files; #Open the directory opendir(AMHANDLE,$path); #iterate over the file handle while(my $file = readdir(AMHANDLE)) { #print $file ."\n"; #If the file is a folder then just echo it if(-d $path.$file) { print "$file is a folder\n"; } else { #Else push it onto the files array push @files,$file; } } #Close the handle closedir(AMHANDLE); #Echo the contents of the @files array foreach my $item(@files) { print $item . "\n"; }
Yes I know that in *NIX that directories are just special case files, but I didn't know if the poster meant files or simply the contents. Please understand that I'm not trying to sound like a know-it-all because everyone probably knows by now that I'm not. I just wanted to offer a few other tidbits of knowledge to AM.
In reply to Re: Re: split to get the dir name
by Grygonos
in thread split to get the dir name
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |