Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Find and C:/

Reply
Thread Tools

Find and C:/

 
 
Robert McGraw
Guest
Posts: n/a
 
      03-29-2006

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



 
Reply With Quote
 
 
 
 
A. Sinan Unur
Guest
Posts: n/a
 
      03-29-2006
"Robert McGraw" <(E-Mail Removed)> wrote in
news:e0ck2s$nhk$(E-Mail Removed):

> 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 <(E-Mail Removed)>
(remove .invalid and reverse each component for email address)

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

 
Reply With Quote
 
 
 
 
MSG
Guest
Posts: n/a
 
      03-29-2006
A. Sinan Unur wrote:
> "Robert McGraw" <(E-Mail Removed)> wrote in
> news:e0ck2s$nhk$(E-Mail Removed):
>
> > 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 <(E-Mail Removed)>
> (remove .invalid and reverse each component for email address)
>
> comp.lang.perl.misc guidelines on the WWW:
> http://augustmail.com/~tadmc/clpmisc...uidelines.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.

 
Reply With Quote
 
A. Sinan Unur
Guest
Posts: n/a
 
      03-29-2006
"MSG" <(E-Mail Removed)> wrote in news:1143602867.729691.243920
@v46g2000cwv.googlegroups.com:

> A. Sinan Unur wrote:
>> "Robert McGraw" <(E-Mail Removed)> wrote in
>> news:e0ck2s$nhk$(E-Mail Removed):
>>
>> > 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 <(E-Mail Removed)>
(remove .invalid and reverse each component for email address)

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

 
Reply With Quote
 
MSG
Guest
Posts: n/a
 
      03-29-2006
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.

 
Reply With Quote
 
Robert McGraw
Guest
Posts: n/a
 
      03-29-2006
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> A. Sinan Unur wrote:
>> "Robert McGraw" <(E-Mail Removed)> wrote in
>> news:e0ck2s$nhk$(E-Mail Removed):
>>
>> > 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 <(E-Mail Removed)>
>> (remove .invalid and reverse each component for email address)
>>
>> comp.lang.perl.misc guidelines on the WWW:
>> http://augustmail.com/~tadmc/clpmisc...uidelines.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.
>



 
Reply With Quote
 
alex
Guest
Posts: n/a
 
      03-29-2006
MSG wrote:
> A. Sinan Unur wrote:
> > "Robert McGraw" <(E-Mail Removed)> wrote in
> > news:e0ck2s$nhk$(E-Mail Removed):
> >
> > > 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 <(E-Mail Removed)>
> > (remove .invalid and reverse each component for email address)
> >
> > comp.lang.perl.misc guidelines on the WWW:
> > http://augustmail.com/~tadmc/clpmisc...uidelines.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:\/\//;

 
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 3 02-14-2011 05:28 AM
How to exclude action of Find::Find::find in subdirectories withknown names? vdvorkin Perl Misc 0 02-10-2011 05:18 PM
How to find which button was clicked in a repeater itemtemplate and find the value of textbox AlecL ASP .Net 3 04-11-2007 10:52 PM
Can some one Explain How To Find File and Leech them Accully How to find all Articals Related to that binary callejachris@tpg.com.au Computer Support 2 12-04-2005 02:15 PM
Find.find does not find orphaned links? Wybo Dekker Ruby 1 11-15-2005 02:50 PM



Advertisments