Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

RE: file wildcards in Win32

by barZion (Beadle)
on Jun 16, 2000 at 21:42 UTC ( #18508=note: print w/replies, xml ) Need Help??


in reply to file wildcards in Win32

This should print out all the filenames with a .h or .c extension on Win32 in a specified subdirectory. Naturally, you would want to tweak it to suit your needs, but it finds the extensions quite nicely.

use Win32::Process; print "Enter the subdirectory you'd like to parse: "; $path = <STDIN>; chomp( $path ); $prefix = "C:\\Projects\\Source\\"; $path = "$prefix$path"; $path = "." unless $path; opendir( DIR, $path ) or die "Can't open $path: $!"; while ( $entry = readdir( DIR ) ) { $type = ( -d "$path\\$entry" ) ? "dir" : "file"; # $path is crucia +l! if( $entry =~ /\.h|\.c$/ ){ print "$entry\n"; } } closedir( DIR );

Replies are listed 'Best First'.
RE: RE: file wildcards in Win32
by flyfishin (Monk) on Jun 17, 2000 at 00:08 UTC
    This will print all files that end in .h* or just .c. It will list .html files .htm files, etc. Surround the \.h|\.c with parens. Change
    if ( $entry =~ /\.h|\.c$) {
    to
    if ( $entry =~ /(\.h|\.c)$) {
    It also won't catch files that end in .H or .C if for some reason those are in caps. You can adjust accordingly.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://18508]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2021-02-25 14:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?