Advertisement
Guest User

Untitled

a guest
Jul 5th, 2015
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5. use Getopt::Long;
  6. my $opt_section;
  7. my $opt_content;
  8. my $opt_help = 0;
  9.  
  10. &GetOptions (
  11. "help" => $opt_help,
  12. "section:s" => $opt_section,
  13. "content:s" => $opt_content,
  14. );
  15.  
  16. if ($opt_help) {
  17. print "USAGE: file.pl -section <section> -content <content> n ";
  18.  
  19. exit;}
  20.  
  21. my $dir ="/home/priya/scripts/test/${opt_section}/${opt_content}/latest"; #base directory to look up for the files
  22.  
  23. print"$dir n";
  24.  
  25. opendir(DIR, $dir) or die "Unable to read Directory : $!";
  26. while (my $file = readdir(DIR)) {
  27. #Only files not subdirectories
  28. next unless (-f "$dir/$file");
  29. #Use a regular expression to find files ending in .txt
  30. $file =~ m/^${opt_section}.+txt$/i;
  31. print "$file n";
  32.  
  33. closedir(DIR);
  34. }
  35. exit 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement