UNIX Find on Windows

Discussion in 'Perl Misc' started by Brian, Feb 10, 2004.

  1. Brian

    Brian Guest

    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
    Brian, Feb 10, 2004
    #1
    1. Advertising

  2. Brian <> 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.
    Eric Schwartz, Feb 10, 2004
    #2
    1. Advertising

  3. Eric Schwartz <> wrote:
    > Brian <> 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
    Perl programming
    Fort Worth, Texas
    Tad McClellan, Feb 10, 2004
    #3
  4. Brian

    l v Guest

    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
    l v, Feb 11, 2004
    #4
  5. On Tue, 10 Feb 2004 16:51:30 -0700, Eric Schwartz <>
    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"
    Michele Dondi, Feb 11, 2004
    #5
  6. On Tue, 10 Feb 2004 23:13:36 GMT, Brian
    <> 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"
    Michele Dondi, Feb 11, 2004
    #6
  7. Brian

    Brian Guest

    Thank you Eric.

    Eric Schwartz wrote:
    >
    > Brian <> 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.
    Brian, Feb 11, 2004
    #7
  8. Brian

    Brian Guest

    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
    > <> 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"
    Brian, Feb 11, 2004
    #8
  9. I.E. wrote:
    > On Tue, 10 Feb 2004 23:13:36 GMT, 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

    >
    > 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");'
    Trent Curry, Feb 18, 2004
    #9
  10. Brian

    Angel Guest

    Brian <> wrote in message news:<>...
    > 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: " *.*
    Angel, Feb 22, 2004
    #10
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    12
    Views:
    1,613
    Dave Thompson
    Jan 10, 2005
  2. Replies:
    18
    Views:
    607
    Dave Thompson
    Jan 10, 2005
  3. Wybo Dekker
    Replies:
    1
    Views:
    337
    Yukihiro Matsumoto
    Nov 15, 2005
  4. Robert Wallace

    my own perl "dos->unix"/"unix->dos"

    Robert Wallace, Jan 21, 2004, in forum: Perl Misc
    Replies:
    7
    Views:
    265
    Michele Dondi
    Jan 22, 2004
  5. vdvorkin
    Replies:
    0
    Views:
    388
    vdvorkin
    Feb 10, 2011
Loading...

Share This Page