UNIX Find on Windows

B

Brian

I'm fairly new to using Perl on Windows. I need to find all of the
files in a folder and its sub folders that match a pattern. On UNIX I'd
do:

$FOUND = `find $DIRROOT -name "$PATTERN" -print`;

Is there a way to do this on Windows using Perl and/or native Windows
commands?

Brian
 
E

Eric Schwartz

Brian said:
I'm fairly new to using Perl on Windows. I need to find all of the
files in a folder and its sub folders that match a pattern. On UNIX I'd
do:

$FOUND = `find $DIRROOT -name "$PATTERN" -print`;

Is there a way to do this on Windows using Perl and/or native Windows
commands?

perldoc File::Find

also, see find2perl (in the standard distribution on Unix; I'd assume
also on Windows), which converts find commands into equivalent (but
not necessarily optimal) Perl programs that use File::Find.

-=Eric
 
L

l v

Brian said:
I'm fairly new to using Perl on Windows. I need to find all of the
files in a folder and its sub folders that match a pattern. On UNIX I'd
do:

$FOUND = `find $DIRROOT -name "$PATTERN" -print`;

Is there a way to do this on Windows using Perl and/or native Windows
commands?

Brian
If you must backtic

$FOUND = `dir /b /s c:\\dir\\*.txt`;

/b give just the file name
/s search sub dirs

However, depending on how much of a pattern $PATTERN is, you might want
to use File::Find as others have suggested.

Len
 
M

Michele Dondi

also, see find2perl (in the standard distribution on Unix; I'd assume
also on Windows), which converts find commands into equivalent (but

Yes, it's there!


Michele
 
M

Michele Dondi

$FOUND = `find $DIRROOT -name "$PATTERN" -print`;

BTW, it may be an idiosincrasy of mine, but I'd rather open() a find
cmd in pipe and read 'while said:
Is there a way to do this on Windows using Perl and/or native Windows
commands?

Using Perl: File::Find. Using native Windows commands: dir /b [/s]
(but may not do exactlty what you mean!). Alternatively I, for one,
have a straight find port from UNXUTILS.

But AFAICT I've never used a statement like the one above, the
rationale being *IMHO* that if the task is simple enough to fit nicely
in a series of piped commands on the cmd line, then find is the right
tool for this, and Perl may not even be necessary whereas if the task
is complex enough to deserve the full power of Perl, then I'd use
File::Find instead.


Michele
 
B

Brian

Thank you Eric.

Eric said:
perldoc File::Find

also, see find2perl (in the standard distribution on Unix; I'd assume
also on Windows), which converts find commands into equivalent (but
not necessarily optimal) Perl programs that use File::Find.

-=Eric
 
B

Brian

Thanks. I'll look at File::Find. This is a part of a fairly complex
script that I'm porting from UNIX to Windows. I'm trying to remove all
of the backtick/system commands that I can to make to portable.

Michele said:
$FOUND = `find $DIRROOT -name "$PATTERN" -print`;

BTW, it may be an idiosincrasy of mine, but I'd rather open() a find
cmd in pipe and read 'while said:
Is there a way to do this on Windows using Perl and/or native Windows
commands?

Using Perl: File::Find. Using native Windows commands: dir /b [/s]
(but may not do exactlty what you mean!). Alternatively I, for one,
have a straight find port from UNXUTILS.

But AFAICT I've never used a statement like the one above, the
rationale being *IMHO* that if the task is simple enough to fit nicely
in a series of piped commands on the cmd line, then find is the right
tool for this, and Perl may not even be necessary whereas if the task
is complex enough to deserve the full power of Perl, then I'd use
File::Find instead.

Michele
--
you'll see that it shouldn't be so. AND, the writting as usuall is
fantastic incompetent. To illustrate, i quote:
- Xah Lee trolling on clpmisc,
"perl bug File::Basename and Perl's nature"
 
T

Trent Curry

I.E. said:
Have you given Cygwin a try? www.cygwin.com

Find seems to work well in cygwin, but be aware some commands are
actually wrappers of the built-in Windows equivelent. Such as netstat.
This may be going a little off scope, I just mean it a warning to anyone
who mistakenly has the impression that everything in it is pure Unix.
There was a discussion on this a while ago in one of the Unix groups.

--
Trent Curry

perl -e
'($s=qq/e29716770256864702379602c6275605/)=~s!([0-9a-f]{2})!pack("h2",$1
)!eg;print(reverse("$s")."\n");'
 
A

Angel

Brian said:
I'm fairly new to using Perl on Windows. I need to find all of the
files in a folder and its sub folders that match a pattern. On UNIX I'd
do:

$FOUND = `find $DIRROOT -name "$PATTERN" -print`;

Is there a way to do this on Windows using Perl and/or native Windows
commands?

Brian

Hi Brian,

If you want to find all of the files in a folder and its sub folders
that match
a pattern on Windows using Perl and/or native Windows commands I
cannot help.
I just do not have enough experience with Perl yet.

If the task is just to find all of the files in a folder and its sub
folders that
match a pattern no matter what kind of tool you will use, I would
suggest egrep.

egrep for Windows is a part of "GNU utilities for Win32". You can
download it from here:

http://unxutils.sourceforge.net/

You can use something like this:

egrep -lr PATTERN *.*

for example:

egrep -lr "^From|Subject|Date: " *.*
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top