For Programmers: Free Programming Magazines  


Home > Archive > PERL Miscellaneous > March 2006 > Find and C:/









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Find and C:/
Robert McGraw

2006-03-28, 7:00 pm


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



A. Sinan Unur

2006-03-28, 7:00 pm

"Robert McGraw" <rmcgraw@math.purdue.edu> wrote in
news:e0ck2s$nhk$1@mailhub227.itcs.purdue.edu:

> 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 <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://augustmail.com/~tadmc/clpmis...guidelines.html

MSG

2006-03-28, 9:59 pm

A. Sinan Unur wrote:
> "Robert McGraw" <rmcgraw@math.purdue.edu> wrote in
> news:e0ck2s$nhk$1@mailhub227.itcs.purdue.edu:
>
>
> 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 <1usa@llenroc.ude.invalid>
> (remove .invalid and reverse each component for email address)
>
> comp.lang.perl.misc guidelines on the WWW:
> http://augustmail.com/~tadmc/clpmis...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.

A. Sinan Unur

2006-03-29, 4:00 am

"MSG" <OliverPC@gmail.com> wrote in news:1143602867.729691.243920
@v46g2000cwv.googlegroups.com:

> A. Sinan Unur wrote:
OS[color=darkred]

....[color=darkred]

Please don't quote signatures.
[color=darkred]
> 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 <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://augustmail.com/~tadmc/clpmis...guidelines.html

MSG

2006-03-29, 4:00 am

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.

Robert McGraw

2006-03-29, 7:00 pm

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" <OliverPC@gmail.com> wrote in message
news:1143602867.729691.243920@v46g2000cwv.googlegroups.com...
> A. Sinan Unur wrote:
>
> 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.
>



alex

2006-03-29, 7:00 pm

MSG wrote:
> A. Sinan Unur wrote:
>
> 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:\/\//;

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com