Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading from dirs?

Status
Not open for further replies.

Guest_imported

New member
Joined
Jan 1, 1970
Messages
0
How do i read the file names from a directory? how do iopen it?

open (MYDIR, "usr/local/bin/mydir") || die "Failed to open dir $!"; ?

would this leave me with <MYDIR> containing all the file names in that directory?

could i then use

for($i; <MYDIR>; $i++)
{
$files[$i] = split (/.dat/, $_);
}

to put them into an array removing the .dat extentions?

thanks
 
You would not use the open() function, but rather the opendir() function.

Like so:

[tt]
opendir(DIR,&quot;usr/local/bin/mydir&quot;) || die(&quot;failed to open dir: $!&quot;);
while($var = readdir(DIR)) {
$var = split (/.dat/, $var);
}
closedir(DIR);
[/tt]

Hope this helps.

-Vic

vic cherubini
krs-one@cnunited.com
====
Knows: Perl, HTML, JavScript, C/C++, PHP, Flash
====
 
easier to use the builtin globbing, like this:

while(<*>){
[tab]print;
} Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
vcherubini thank you thank you thank you!!!!!
i've been trying to do this for ages!
Greatly appricated!
Sib
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top