Find and C:/

R

Robert McGraw

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

A. Sinan Unur

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 <[email protected]>
(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
 
M

MSG

A. Sinan Unur said:
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 <[email protected]>
(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.
 
A

A. Sinan Unur


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 <[email protected]>
(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
 
M

MSG

A. Sinan Unur said:
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.
 
R

Robert McGraw

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
 
A

alex

MSG said:
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:\/\//;
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top