How do I print all .pdf files names to an output file with command line?

This seems easy in Linux, but I'm trying to print the names of *.pdf files within a directory and its subdirectories to an output file. I have Perl installed on my Windows machine.

What's a simple way to do this?


Not much different than Linux.

dir *.pdf > fileyouwant.txt

If you only want the filenames, you can do that with

dir/b *.pdf > fileyouwant.txt

If you also want subdirs,

dir/s/b *.pdf > fileyouwant.txt

If you aren't in that directory to start with

dir/s/b C:\Path\*.pdf > fileyouwant.txt

use strict;
use warnings;
use File::Find;

my $dirname = shift or die "Usage: $0 dirname >outputfile";

File::Find::find( sub {
    print $File::Find::name, "\n" if $File::Find::name =~ /\.pdf\z/
}, $dirname );

File::Find::Rule is often nicer to use than File::Find.

use File::Find::Rule;

my $rule = File::Find::Rule->file()->name('*.pdf')->start('C:/Path/');
while (defined (my $pdf = $rule->match)) {
    print "$pdf\n";

or simply

use File::Find::Rule;

print "$_\n" for File::Find::Rule->file()->name('*.pdf')->in('C:/Path/');

Using Perl, you should almost certainly be using the File::Find core module.

See the File::Glob module.


use File::Glob ':glob'; # Override glob built-in.                          
print join("\n",glob("*.pdf"));

Need Your Help

How to get the hidden element value in capybara?

ruby capybara

I need to get the value of a hidden element.

bind a jquery function to fancybox .close() event

jquery function fancybox bind

I would like to trigger a simple jQuery function based on a fancybox closing. it is the only fancybox on the page