| | |
parsing multiple files in current directory
![]() |
•
•
Join Date: Apr 2007
Posts: 1
Reputation:
Solved Threads: 0
Hi,
If it's not too much trouble I would appreciate some help with this - how can I iterate through multiple files in the current directory, opening one after another? For example all files with a name matching students_*.html format. I'm not concerned with files contained in sub-directories.
I've searched for a solution but haven't found anything; if this has already been answered please show me where.
Thanks in advance for your time.
If it's not too much trouble I would appreciate some help with this - how can I iterate through multiple files in the current directory, opening one after another? For example all files with a name matching students_*.html format. I'm not concerned with files contained in sub-directories.
I've searched for a solution but haven't found anything; if this has already been answered please show me where.
Thanks in advance for your time.
two ways to go about it:
Perl Syntax (Toggle Plain Text)
chdir("path/to/dir") or die "$!"; opendir (DIR, ".") or die "$!"; my @files = grep {/students_.*?\.html/} readdir DIR; close DIR; { local @ARGV = @files; while(<>){ #each file will be read line by line here } }
Perl Syntax (Toggle Plain Text)
opendir (DIR, "path/to/dir") or die "$!"; my @files = grep {/students_.*?\.html/} readdir DIR; close DIR; foreach my $file (@files) { open(FH,"path/to/$file") or die "$!"; while (<FH>){ #read file line by line here } close(FH); }
•
•
Join Date: Nov 2009
Posts: 1
Reputation:
Solved Threads: 0
What would be the same for multiple sub directories?
Thanks in Advance,
Thirilog
Thanks in Advance,
Thirilog
•
•
•
•
two ways to go about it:
Perl Syntax (Toggle Plain Text)
chdir("path/to/dir") or die "$!"; opendir (DIR, ".") or die "$!"; my @files = grep {/students_.*?\.html/} readdir DIR; close DIR; { local @ARGV = @files; while(<>){ #each file will be read line by line here } }
Perl Syntax (Toggle Plain Text)
opendir (DIR, "path/to/dir") or die "$!"; my @files = grep {/students_.*?\.html/} readdir DIR; close DIR; foreach my $file (@files) { open(FH,"path/to/$file") or die "$!"; while (<FH>){ #read file line by line here } close(FH); }
![]() |
Similar Threads
- Eliminating Whitespace characters while parsing XML Files using DOM (Java)
- problems writing multiple files (Perl)
- Quick Reference for Linux Commands (Getting Started and Choosing a Distro)
- Create EXE to delete files in TEMP Directory (Windows NT / 2000 / XP)
- Need DOS help (Windows 95 / 98 / Me)
- Basic Yellow Dog 3.0 questions (*nix Software)
- How to Rename Multiple Files with Windows Explorer (Windows tips 'n' tweaks)
- Tutorials for Linux (*nix Software)
Other Threads in the Perl Forum
- Previous Thread: matching and replacing workaround
- Next Thread: Match phone number
| Thread Tools | Search this Thread |





