Converting Unix paths to windows
Hi, I am writing a script to be used on Windows and many different flavors of Unix. I am looking for a good way to convert Unix paths to Windows. Any Ideas? Thanks, Daryl J. Hoyt Performance Engineer Geodesic Systems http://www.geodesic.com [EMAIL PROTECTED]
Re: Converting Unix paths to windows
At 10:22 27.06.2001 -0500, Daryl Hoyt wrote: >Hi, > I am writing a script to be used on Windows and many different flavors >of Unix. I am looking for a good way to convert Unix paths to Windows. Any >Ideas? What do you mean exactly. If you just mean converting "\" to "/" and getting rid of the drive you can do this: my $sPath = "C:\\foo\\bar"; $sPath =~ s/^[a-z]+://i; $sPath =~ s/\\/\//g; print $sPath; Aaron Craig Programming iSoftitler.com
RE: Converting Unix paths to windows
As a side note, you can still use forward slash "/" instead of "\" in Windows. They are compatible with all internal Windows API. Reasons for this is the history prior to MS-DOS being born. -Robin > -Original Message- > From: Aaron Craig [SMTP:[EMAIL PROTECTED]] > Sent: Wednesday, June 27, 2001 11:50 AM > To: [EMAIL PROTECTED] > Subject: Re: Converting Unix paths to windows > > At 10:22 27.06.2001 -0500, Daryl Hoyt wrote: > >Hi, > > I am writing a script to be used on Windows and many different > flavors > >of Unix. I am looking for a good way to convert Unix paths to Windows. > Any > >Ideas? > > What do you mean exactly. If you just mean converting "\" to "/" and > getting rid of the drive you can do this: > > my $sPath = "C:\\foo\\bar"; > $sPath =~ s/^[a-z]+://i; > $sPath =~ s/\\/\//g; > print $sPath; > Aaron Craig > Programming > iSoftitler.com
Re: Converting Unix paths to windows
On Wednesday, June 27, 2001, at 08:59 AM, [EMAIL PROTECTED] wrote: Hi, I am writing a script to be used on Windows and many different flavors of Unix. I am looking for a good way to convert Unix paths to Windows. Any Ideas? Not exactly an answer to your question, but perhaps something that may be of use to you... The following cross platform snippet (found somewhere on the web, I believe) will return the path of where the script is running. if($0=~m#^(.*)\\#){ $cgidir = "$1"; } # win/dos elsif ($0=~m#^(.*)/# ){ $cgidir = "$1"; } # Unix else {`pwd` =~ /(.*)/; $cgidir = "$1"; } # Unix I'm guessing you could use it to find a base directory, and then do relative stuff from there. You may also be able to use its test blocks to flag whether or not you're on a windows box and construct your relative paths accordingly. There are probably other ways that platform can be determined, but TMTOWTDI seems to be a credo around here. Hope this helps.
Re: Converting Unix paths to windows
On Wed, Jun 27, 2001 at 12:08:26PM -0700, Chuck Ivy wrote: > if($0=~m#^(.*)\\#){ $cgidir = "$1"; } # win/dos > elsif ($0=~m#^(.*)/# ){ $cgidir = "$1"; } # Unix > else {`pwd` =~ /(.*)/; $cgidir = "$1"; } # Unix This is just a less portable implementation of what FindBin.pm does, which comes standard with Perl. Michael -- Administrator www.shoebox.net Programmer, System Administrator www.gallanttech.com --
Re: Converting Unix paths to windows
On Wed, 27 Jun 2001, Daryl Hoyt <[EMAIL PROTECTED]> wrote, > Hi, > I am writing a script to be used on Windows and many different > flavors of Unix. I am looking for a good way to convert Unix paths > to Windows. Any Ideas? use File::Spec; I know your question is about "converting". But I offer you portability so you don't need to convert anything and create two (or more) scripts for two (or more) different systems. Besides, as long as unix2windows *path* is concerned, Perl in Windows treats / correctly, except perhaps the C: drive notation. __END__ -- s::a::n->http(www.trabas.com)