
Peter Van Hoecke
Deleted
Apr 27, 2000, 5:56 AM
Post #2 of 2
(4498 views)
|
Re: Reading directory and a file
[In reply to]
|
Can't Post
|
|
This is a crude version, if you test it and could suggest corrections/clues to improve it, let me know!! Peter.Van_Hoecke@ecom.be #!perl.exe use strict; my($path, @lines, $name, $location, $education, $list, $path); $path = "c:/scripts/onliner/"; #enter the source path her ex. /home/account/ $list = "c:/scripts/onliner/list.txt"; #where the information should end up open OUT, ">$list"; print OUT "Name|Location|Education\n"; #heading of the file while( glob("*") ) # give me all files in this directory { if(-d $_ ) # if it's a directory { chdir $_; if( -f "info.txt") #does the file exist { open(INFO, "info.txt"); @lines = <INFO>; close INFO; $name = $lines[0]; chomp $name; $name =~ s/\w+ *: *//; $location = $lines[1]; chomp $location; $location =~ s/\w+ *: *//; $education = $lines[2]; chomp $education; $education =~ s/\w+ *: *//; print OUT $name . "|" . $location . "|" . $education . "\n"; @lines = undef; # just to be on the safe side... } chdir ".."; } }
|