Generate full path of file names with .cpp, .hpp, .h, .c extension

In perl, given two or more base directories, I need to find files of .cpp, .hpp, .h, .c extension and generate full path like Windows Find tool.

E.g., say I have two or more base directories

C:\foo\bar\
C:\foo\bar\barbar

and I need to generate full path of .cpp, .hpp, .h, .c file names in given base directories.

Those files may exist in C:\foo\bar\bar\foo\bar\foo\, but I know only few base directories as given above

Answers


use File::Find;

find(\&print_names, ('thisdir/one/', 'thatdir/two'));

sub print_names {
    my $name = $File::Find::name;
    print "$name\n"if $name =~ /\.(cpp|hpp|h|c)$/;
}

To convert a file path that uses mixed backward and forward slashes you need to use the File::Spec module. The File::Spec::Functions wrapper module just makes it slightly neater to call the functions it contains.

Try this

use strict;
use warnings;

use File::Find;
use File::Spec::Functions qw/canonpath/;

find(sub {
  print canonpath($File::Find::name), "\n" if -f and /\.[ch](?:pp)?$/;
}, qw{ C:\foo\bar\ C:\foo\bar\barbar });

Need Your Help

how to add series of sql time values in java

java sql time

I have a ResultSet of of Time objects that are the differences between two times. They are in the minute to second range for example "00:01:12" or "00:00:22"

Calling Awk in a shell script

shell awk

I have this command which executes correctly if run directly on the terminal.