vladb has asked for the wisdom of the Perl Monks concerning the following question:

Hail thee!

I haven't coded Perl for Win32 for quite a time now (mostly work on Solaris), therefore, I tend to run into weird problems with common modules and scripts that used to work on Solaris and won't work well (or as expected) on Win32 systems.

One particular problem I have is with File::Find using '/' in file path names, instead of, say, '\' as I thought it would do. Doesn't File::Find do a check on the type of system it is dealing with and then figure out which 'slash' is to be used? I now end up having to do 's/\//\\/g' on my file path to switch all '/' to '\' so that I can actually access those files.

Here's a small snippet from my code:
find(sub { !/$skip_match/ && /$accept_match/ && -f && $handle_onfound->("$File::Find::name", $handle_on +found_args); }, $startdir);
where, $handle_onfound is a handler subroutine and $startdir is set to directory I wish to do my search in. $File::Find::name would always have '/' in it. I'm wondering if any monk out there would know of a way to fix this? I consulted File::Find perldoc but didn't find anything pertaining to this matter.

Thanks for help! ;)

"There is no system but GNU, and Linux is one of its kernels." -- Confession of Faith

Replies are listed 'Best First'.
Re: File::Find uses '/' in path on Win32 system.
by gellyfish (Monsignor) on Mar 10, 2002 at 09:57 UTC

    If you want to keep your code portable you might want to think about using File::Spec to determine what the path separator should be, I think that this is probably what File::Find is doing actually and returning the path separators that it thinks you are expecting (without looking at the code.)

    /J\

      It would make sense if File::Find did that... however, it doesn't. I have a somewhat more portable rewrite that does, but it's quite a bit slower. (It's also supposed to receive a nicer interface at some point.)

      Even in 5.7.3, File::Find only works reliably on Unix and Windows systems. Mac is pretty good.

Re: File::Find uses '/' in path on Win32 system.
by BeernuT (Pilgrim) on Mar 10, 2002 at 06:29 UTC
    On win* you can use '/' in perl instead of having to use '\' or sometimes '\\' to denote a directory.

    UPDATE: i missed what you were getting at. As far as using s!/!\\!g; should be ok for say outputting a list of files to a txt file for later retrieval by another program. But as far as perl is concerned there shouldnt be a problem using '/' instead of '\'.

    sorry for the confusion

    -bn
Re: File::Find uses '/' in path on Win32 system.
by perrin (Chancellor) on Mar 10, 2002 at 16:51 UTC
    You didn't mention whether you're using ActiveState or Cygwin (or something else). They handle paths differently. Cygwin translates paths so that everything looks more unixy and you can use / in your input to it. However, I've had better luck in general with ActiveState which uses standard Win32 paths.

    It's not quite clear to me what the problem is in your example above (you want to use \ in your input, or get / in the output, or what?), but I use File::Spec->canonpath($File::Find::name) in my scripts to correct for these \/ issues. Maybe that will help.