Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > UNIX Find on Windows

Reply
Thread Tools

UNIX Find on Windows

 
 
Brian
Guest
Posts: n/a
 
      02-10-2004
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
 
Reply With Quote
 
 
 
 
Eric Schwartz
Guest
Posts: n/a
 
      02-10-2004
Brian <(E-Mail Removed) > writes:
> 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
--
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
-- Blair Houghton.
 
Reply With Quote
 
 
 
 
Tad McClellan
Guest
Posts: n/a
 
      02-10-2004
Eric Schwartz <(E-Mail Removed)> wrote:
> Brian <(E-Mail Removed) > writes:


>> I need to find all of the
>> files in a folder and its sub folders that match a pattern.


>> Is there a way to do this on Windows using Perl



> perldoc File::Find
>
> also, see find2perl



See also also:

http://www.perl.com/language/ppt/src/find/


--
Tad McClellan SGML consulting
http://www.velocityreviews.com/forums/(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
l v
Guest
Posts: n/a
 
      02-11-2004
Brian wrote:
> 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

 
Reply With Quote
 
Michele Dondi
Guest
Posts: n/a
 
      02-11-2004
On Tue, 10 Feb 2004 16:51:30 -0700, Eric Schwartz <(E-Mail Removed)>
wrote:

>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
--
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"
 
Reply With Quote
 
Michele Dondi
Guest
Posts: n/a
 
      02-11-2004
On Tue, 10 Feb 2004 23:13:36 GMT, Brian
<(E-Mail Removed) > wrote:

>$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 <$fh>' as usual...

>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"
 
Reply With Quote
 
Brian
Guest
Posts: n/a
 
      02-11-2004
Thank you Eric.

Eric Schwartz wrote:
>
> Brian <(E-Mail Removed) > writes:
> > 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
> --
> Come to think of it, there are already a million monkeys on a million
> typewriters, and Usenet is NOTHING like Shakespeare.
> -- Blair Houghton.

 
Reply With Quote
 
Brian
Guest
Posts: n/a
 
      02-11-2004
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 Dondi wrote:
>
> On Tue, 10 Feb 2004 23:13:36 GMT, Brian
> <(E-Mail Removed) > wrote:
>
> >$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 <$fh>' as usual...
>
> >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"

 
Reply With Quote
 
Trent Curry
Guest
Posts: n/a
 
      02-18-2004
I.E. wrote:
> On Tue, 10 Feb 2004 23:13:36 GMT, Brian
> <(E-Mail Removed) > wrote:
>
>> 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

>
> 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");'


 
Reply With Quote
 
Angel
Guest
Posts: n/a
 
      02-22-2004
Brian <(E-Mail Removed) > wrote in message news:<(E-Mail Removed)>...
> 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: " *.*
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to exclude action of Find::Find::find in subdirectories withknown names? vdvorkin Perl Misc 0 02-10-2011 05:18 PM
Find.find does not find orphaned links? Wybo Dekker Ruby 1 11-15-2005 02:50 PM
compile C programs with UNIX system calls (= Unix Programs??) jrefactors@hotmail.com C Programming 18 01-10-2005 03:35 AM
compile C programs with UNIX system calls (= Unix Programs??) jrefactors@hotmail.com C++ 12 01-10-2005 03:35 AM
my own perl "dos->unix"/"unix->dos" Robert Wallace Perl Misc 7 01-22-2004 10:59 PM



Advertisments