Find and C:/

Discussion in 'Perl Misc' started by Robert McGraw, Mar 29, 2006.

  1. I am using ASPerl 5.8.7 on a Window XP hosts.

    my $scandir = "XXX";
    find( \&getfiles, $scandir );

    If $scandir equal to C:/ find starts scanning from C:/Documents and
    Settings/Robert McGraw/

    If I set $scandir equal to C:/xxx then it will start scanning from C:/xxx

    I need to start scanning files from C:/.

    Is this the way it should work? Is there some workaround to allow me to scan
    from C:.


    Thanks


    Robert
    Robert McGraw, Mar 29, 2006
    #1
    1. Advertising

  2. "Robert McGraw" <> wrote in
    news:e0ck2s$nhk$:

    > I am using ASPerl 5.8.7 on a Window XP hosts.
    >
    > my $scandir = "XXX";
    > find( \&getfiles, $scandir );
    >
    > If $scandir equal to C:/ find starts scanning from C:/Documents and
    > Settings/Robert McGraw/
    >
    > If I set $scandir equal to C:/xxx then it will start scanning from
    > C:/xxx
    >
    > I need to start scanning files from C:/.
    >
    > Is this the way it should work?


    The order in which files are returned depends on how the underlying OS
    calls return them. On the other hand, I don't see that:

    D:\Home\asu1\UseNet\clpmisc\cs> cat ff.pl
    #!/usr/bin/perl

    use strict;
    use warnings;

    use File::Find;

    find( \&getfiles, 'C:/' );

    {
    my $count = 0;
    sub getfiles {
    print "$File::Find::name\n";
    exit if ++ $count == 20;
    }
    }

    D:\Home\asu1\UseNet\clpmisc\cs> ff
    C:/
    C:/boot.ini
    C:/BOOTSECT.DOS
    C:/CONFIG.SYS
    C:/hiberfil.sys
    C:/IO.SYS
    C:/MSDOS.SYS
    C:/NTDETECT.COM
    C:/ntldr
    C:/pagefile.sys
    C:/PATCH.REV
    C:/PRELOAD.AAA
    C:/PRELOAD.REV
    C:/settings.xml
    C:/Acer
    C:/Acer/eManager
    C:/Acer/eManager/anbmServ.exe
    C:/Acer/eManager/cpuid_dll.dll
    C:/Acer/eManager/dmstheme.ini
    C:/Acer/eManager/eManager.exe

    Sinan
    --
    A. Sinan Unur <>
    (remove .invalid and reverse each component for email address)

    comp.lang.perl.misc guidelines on the WWW:
    http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
    A. Sinan Unur, Mar 29, 2006
    #2
    1. Advertising

  3. Robert McGraw

    MSG Guest

    A. Sinan Unur wrote:
    > "Robert McGraw" <> wrote in
    > news:e0ck2s$nhk$:
    >
    > > I am using ASPerl 5.8.7 on a Window XP hosts.
    > >
    > > my $scandir = "XXX";
    > > find( \&getfiles, $scandir );
    > >
    > > If $scandir equal to C:/ find starts scanning from C:/Documents and
    > > Settings/Robert McGraw/
    > >
    > > If I set $scandir equal to C:/xxx then it will start scanning from
    > > C:/xxx
    > >
    > > I need to start scanning files from C:/.
    > >
    > > Is this the way it should work?

    >
    > The order in which files are returned depends on how the underlying OS
    > calls return them. On the other hand, I don't see that:
    >
    > D:\Home\asu1\UseNet\clpmisc\cs> cat ff.pl
    > #!/usr/bin/perl
    >
    > use strict;
    > use warnings;
    >
    > use File::Find;
    >
    > find( \&getfiles, 'C:/' );
    >
    > {
    > my $count = 0;
    > sub getfiles {
    > print "$File::Find::name\n";
    > exit if ++ $count == 20;
    > }
    > }
    >
    > D:\Home\asu1\UseNet\clpmisc\cs> ff
    > C:/
    > C:/boot.ini
    > C:/BOOTSECT.DOS
    > C:/CONFIG.SYS
    > C:/hiberfil.sys
    > C:/IO.SYS
    > C:/MSDOS.SYS
    > C:/NTDETECT.COM
    > C:/ntldr
    > C:/pagefile.sys
    > C:/PATCH.REV
    > C:/PRELOAD.AAA
    > C:/PRELOAD.REV
    > C:/settings.xml
    > C:/Acer
    > C:/Acer/eManager
    > C:/Acer/eManager/anbmServ.exe
    > C:/Acer/eManager/cpuid_dll.dll
    > C:/Acer/eManager/dmstheme.ini
    > C:/Acer/eManager/eManager.exe
    >
    > Sinan
    > --
    > A. Sinan Unur <>
    > (remove .invalid and reverse each component for email address)
    >
    > comp.lang.perl.misc guidelines on the WWW:
    > http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html


    You will see the problem only if you run your code from a non-root
    directory!!

    I am glad that Robert brought up this issue since I have had the
    exact same problem as tested on a number of WinXP computers.
    ( haven't tried on any other versions of Windows yet ).
    My temporary "hack" is to use double slashes or double
    backslashes like this :
    find(\&wanted, "C://") or find(\&wanted, "C:\\")
    They don't make sense but either one works!

    Hopefully someone else out there know the answer/fix.
    MSG, Mar 29, 2006
    #3
  4. "MSG" <> wrote in news:1143602867.729691.243920
    @v46g2000cwv.googlegroups.com:

    > A. Sinan Unur wrote:
    >> "Robert McGraw" <> wrote in
    >> news:e0ck2s$nhk$:
    >>
    >> > I am using ASPerl 5.8.7 on a Window XP hosts.
    >> >
    >> > my $scandir = "XXX";
    >> > find( \&getfiles, $scandir );
    >> >
    >> > If $scandir equal to C:/ find starts scanning from C:/Documents and
    >> > Settings/Robert McGraw/
    >> >
    >> > If I set $scandir equal to C:/xxx then it will start scanning from
    >> > C:/xxx
    >> >
    >> > I need to start scanning files from C:/.
    >> >
    >> > Is this the way it should work?

    >>
    >> The order in which files are returned depends on how the underlying

    OS
    >> calls return them. On the other hand, I don't see that:
    >>
    >> D:\Home\asu1\UseNet\clpmisc\cs> cat ff.pl
    >> #!/usr/bin/perl
    >>
    >> use strict;
    >> use warnings;
    >>
    >> use File::Find;
    >>
    >> find( \&getfiles, 'C:/' );
    >>
    >> {
    >> my $count = 0;
    >> sub getfiles {
    >> print "$File::Find::name\n";
    >> exit if ++ $count == 20;
    >> }
    >> }
    >>
    >> D:\Home\asu1\UseNet\clpmisc\cs> ff
    >> C:/
    >> C:/boot.ini


    ....
    >> --


    Please don't quote signatures.

    > You will see the problem only if you run your code from a non-root
    > directory!!


    Why the double exclamation?

    Did you notice the directory in which I ran that script?

    > I am glad that Robert brought up this issue since I have had the
    > exact same problem as tested on a number of WinXP computers.
    > ( haven't tried on any other versions of Windows yet ).
    > My temporary "hack" is to use double slashes or double
    > backslashes like this :
    > find(\&wanted, "C://") or find(\&wanted, "C:\\")
    > They don't make sense but either one works!
    >
    > Hopefully someone else out there know the answer/fix.


    So far, neither of you have posted an actual, complete script with
    sample output that exhibits the "problem".

    Sinan

    --
    A. Sinan Unur <>
    (remove .invalid and reverse each component for email address)

    comp.lang.perl.misc guidelines on the WWW:
    http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
    A. Sinan Unur, Mar 29, 2006
    #4
  5. Robert McGraw

    MSG Guest

    A. Sinan Unur wrote:
    > Did you notice the directory in which I ran that script?

    Sorry I didn't see it!
    But it makes it even more puzzling as to why the problem doesn't
    occur on some computers? I had expected that it would occur on
    any win32 computers since I saw this problem in last month on at least
    3 different PCs owned by different people. The perl versions are all
    5.8.6 or 5.8.7.
    >
    > So far, neither of you have posted an actual, complete script with
    > sample output that exhibits the "problem".
    >

    The script I ran was 100% yours, cut and paste from your first post,
    renamed to "filefind.pl".
    Here is one result that demonstrates the problem:

    C:\Perl\filefind.pl
    C:
    C:/aaa.txt
    C:/filefind.pl
    C:/pod2htmd.tmp
    C:/pod2htmi.tmp
    C:/bin
    C:/bin/a2p.exe
    C:/bin/c2ph.bat
    C:/bin/config.pl
    C:/bin/cpan.bat
    C:/bin/crc32
    C:/bin/crc32.bat
    C:/bin/dbiprof
    C:/bin/dbiprof.bat
    C:/bin/dbiproxy
    C:/bin/dbiproxy.bat
    C:/bin/dprofpp.bat
    C:/bin/enc2xs.bat
    C:/bin/exetype.bat
    C:/bin/find2perl.bat

    It can be seen that the script "filefind.pl" doesn't read the root C:\,
    instead it reads current directory C:\Perl.

    C:\Perl\dir
    Volume in drive C has no label.
    Volume Serial Number is 78E5-0958

    Directory of C:\Perl

    03/28/2006 08:33 PM <DIR> .
    03/28/2006 08:33 PM <DIR> ..
    03/28/2006 08:33 PM 0 aaa.txt
    03/24/2006 11:06 AM <DIR> bin
    05/16/2005 05:53 PM <DIR> eg
    03/28/2006 06:25 PM 227 filefind.pl
    05/16/2005 05:54 PM <DIR> html
    05/16/2005 05:53 PM <DIR> lib
    05/16/2005 05:53 PM 37,956 pod2htmd.tmp
    05/16/2005 05:53 PM 17,147 pod2htmi.tmp
    11/05/2004 09:40 PM <DIR> site
    4 File(s) 55,330 bytes
    7 Dir(s) 1,660,362,752 bytes free

    If I copy the script to D:\ and run it from there, I get back
    20 files names from c:\windows\system32 directory.
    MSG, Mar 29, 2006
    #5
  6. The solution of putting C:// in place of C:/ did the trick.

    It is obvious once you understand it. NOT.

    Thanks for your reply.

    Robert


    "MSG" <> wrote in message
    news:...
    > A. Sinan Unur wrote:
    >> "Robert McGraw" <> wrote in
    >> news:e0ck2s$nhk$:
    >>
    >> > I am using ASPerl 5.8.7 on a Window XP hosts.
    >> >
    >> > my $scandir = "XXX";
    >> > find( \&getfiles, $scandir );
    >> >
    >> > If $scandir equal to C:/ find starts scanning from C:/Documents and
    >> > Settings/Robert McGraw/
    >> >
    >> > If I set $scandir equal to C:/xxx then it will start scanning from
    >> > C:/xxx
    >> >
    >> > I need to start scanning files from C:/.
    >> >
    >> > Is this the way it should work?

    >>
    >> The order in which files are returned depends on how the underlying OS
    >> calls return them. On the other hand, I don't see that:
    >>
    >> D:\Home\asu1\UseNet\clpmisc\cs> cat ff.pl
    >> #!/usr/bin/perl
    >>
    >> use strict;
    >> use warnings;
    >>
    >> use File::Find;
    >>
    >> find( \&getfiles, 'C:/' );
    >>
    >> {
    >> my $count = 0;
    >> sub getfiles {
    >> print "$File::Find::name\n";
    >> exit if ++ $count == 20;
    >> }
    >> }
    >>
    >> D:\Home\asu1\UseNet\clpmisc\cs> ff
    >> C:/
    >> C:/boot.ini
    >> C:/BOOTSECT.DOS
    >> C:/CONFIG.SYS
    >> C:/hiberfil.sys
    >> C:/IO.SYS
    >> C:/MSDOS.SYS
    >> C:/NTDETECT.COM
    >> C:/ntldr
    >> C:/pagefile.sys
    >> C:/PATCH.REV
    >> C:/PRELOAD.AAA
    >> C:/PRELOAD.REV
    >> C:/settings.xml
    >> C:/Acer
    >> C:/Acer/eManager
    >> C:/Acer/eManager/anbmServ.exe
    >> C:/Acer/eManager/cpuid_dll.dll
    >> C:/Acer/eManager/dmstheme.ini
    >> C:/Acer/eManager/eManager.exe
    >>
    >> Sinan
    >> --
    >> A. Sinan Unur <>
    >> (remove .invalid and reverse each component for email address)
    >>
    >> comp.lang.perl.misc guidelines on the WWW:
    >> http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html

    >
    > You will see the problem only if you run your code from a non-root
    > directory!!
    >
    > I am glad that Robert brought up this issue since I have had the
    > exact same problem as tested on a number of WinXP computers.
    > ( haven't tried on any other versions of Windows yet ).
    > My temporary "hack" is to use double slashes or double
    > backslashes like this :
    > find(\&wanted, "C://") or find(\&wanted, "C:\\")
    > They don't make sense but either one works!
    >
    > Hopefully someone else out there know the answer/fix.
    >
    Robert McGraw, Mar 29, 2006
    #6
  7. Robert McGraw

    alex Guest

    MSG wrote:
    > A. Sinan Unur wrote:
    > > "Robert McGraw" <> wrote in
    > > news:e0ck2s$nhk$:
    > >
    > > > I am using ASPerl 5.8.7 on a Window XP hosts.
    > > >
    > > > my $scandir = "XXX";
    > > > find( \&getfiles, $scandir );
    > > >
    > > > If $scandir equal to C:/ find starts scanning from C:/Documents and
    > > > Settings/Robert McGraw/
    > > >
    > > > If I set $scandir equal to C:/xxx then it will start scanning from
    > > > C:/xxx
    > > >
    > > > I need to start scanning files from C:/.
    > > >
    > > > Is this the way it should work?

    > >
    > > The order in which files are returned depends on how the underlying OS
    > > calls return them. On the other hand, I don't see that:
    > >
    > > D:\Home\asu1\UseNet\clpmisc\cs> cat ff.pl
    > > #!/usr/bin/perl
    > >
    > > use strict;
    > > use warnings;
    > >
    > > use File::Find;
    > >
    > > find( \&getfiles, 'C:/' );
    > >
    > > {
    > > my $count = 0;
    > > sub getfiles {
    > > print "$File::Find::name\n";
    > > exit if ++ $count == 20;
    > > }
    > > }
    > >
    > > D:\Home\asu1\UseNet\clpmisc\cs> ff
    > > C:/
    > > C:/boot.ini
    > > C:/BOOTSECT.DOS
    > > C:/CONFIG.SYS
    > > C:/hiberfil.sys
    > > C:/IO.SYS
    > > C:/MSDOS.SYS
    > > C:/NTDETECT.COM
    > > C:/ntldr
    > > C:/pagefile.sys
    > > C:/PATCH.REV
    > > C:/PRELOAD.AAA
    > > C:/PRELOAD.REV
    > > C:/settings.xml
    > > C:/Acer
    > > C:/Acer/eManager
    > > C:/Acer/eManager/anbmServ.exe
    > > C:/Acer/eManager/cpuid_dll.dll
    > > C:/Acer/eManager/dmstheme.ini
    > > C:/Acer/eManager/eManager.exe
    > >
    > > Sinan
    > > --
    > > A. Sinan Unur <>
    > > (remove .invalid and reverse each component for email address)
    > >
    > > comp.lang.perl.misc guidelines on the WWW:
    > > http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html

    >
    > You will see the problem only if you run your code from a non-root
    > directory!!
    >
    > I am glad that Robert brought up this issue since I have had the
    > exact same problem as tested on a number of WinXP computers.
    > ( haven't tried on any other versions of Windows yet ).
    > My temporary "hack" is to use double slashes or double
    > backslashes like this :
    > find(\&wanted, "C://") or find(\&wanted, "C:\\")
    > They don't make sense but either one works!
    >



    > Hopefully someone else out there know the answer/fix.


    IIRC this is because File::Find strips the trailing slash off
    the pathname, then chdir's to this directory.
    This is fine except for the case of the root drive "C:/" as
    chdir 'c:' is not the same as chdir 'c:/'. The former simply
    changes the drive and is a NOP if you're already on C:.,
    while the latter changes the drive to c: _and_ goes to
    the root of that drive.

    I came up with the same solution as you; that is to add another
    slash to the directory name if it matches the root drive ie.

    $dir =~ s/^(\w):\/?$/$1:\/\//;
    alex, Mar 29, 2006
    #7
    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. AlecL
    Replies:
    3
    Views:
    1,187
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Apr 11, 2007
  2. Wybo Dekker
    Replies:
    1
    Views:
    338
    Yukihiro Matsumoto
    Nov 15, 2005
  3. rtilley

    Find.find and files in cwd

    rtilley, Mar 21, 2006, in forum: Ruby
    Replies:
    12
    Views:
    202
    ChrisH
    Mar 22, 2006
  4. vdvorkin
    Replies:
    0
    Views:
    389
    vdvorkin
    Feb 10, 2011
  5. vdvorkin
    Replies:
    3
    Views:
    795
    vdvorkin
    Feb 14, 2011
Loading...

Share This Page