473,513 Members | 2,595 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Convert between Windows style paths and POSIX style paths

Does anyone have a function to convert back and forth between
NT style paths and POSIX style? It seems trivial, but
I want to make sure I don't overlook some obscure detail.
Is it a simple matter of translating / and \ characters?

FYI, I need a Python function that does what cygpath does so that
I can run a script on either NT or UNIX or Cygwin.
I want my config files use one style of path.

Yours,
Noah
Jul 18 '05 #1
5 18089
Noah wrote:

Does anyone have a function to convert back and forth between
NT style paths and POSIX style? It seems trivial, but
I want to make sure I don't overlook some obscure detail.
Is it a simple matter of translating / and \ characters?

FYI, I need a Python function that does what cygpath does so that
I can run a script on either NT or UNIX or Cygwin.
I want my config files use one style of path.


You can use forward slashes in paths under Win32, except at the
command prompt.

Even if you switch to use all forward slashes, however, what do
you plan to do about drive letters? There is no obvious mapping
to anything under POSIX, I think. Are you planning on disallowing
paths that go anywhere but the current drive under NT?

-Peter
Jul 18 '05 #2

"Peter Hansen" <pe***@engcorp.com> wrote in message
news:3F***************@engcorp.com...
Noah wrote:

Does anyone have a function to convert back and forth between
NT style paths and POSIX style? It seems trivial, but
I want to make sure I don't overlook some obscure detail.
Is it a simple matter of translating / and \ characters?

FYI, I need a Python function that does what cygpath does so that
I can run a script on either NT or UNIX or Cygwin.
I want my config files use one style of path.


You can use forward slashes in paths under Win32, except at the
command prompt.

Even if you switch to use all forward slashes, however, what do
you plan to do about drive letters? There is no obvious mapping
to anything under POSIX, I think. Are you planning on disallowing
paths that go anywhere but the current drive under NT?


Well, if you're running on an NT system with Cygwin installed, then the
obvious thing to do (really the only sensible thing to do IMHO) is to use
the mappings provided by Cygwin. These are set up in the registry and
accessed via commands like mount and cygpath, which call functions in
cygwin.dll. Eg my system has the following:

D:\Cygwin <==> /
D:\Local <==> /usr/local

And if you want to do *that* then the easiest way, though not the fastest,
is to run the cygpath command and trap the output. I have modules that do
this in Windows & Cygwin Python, if you (meaning the OP) are interested.
Another way is to access the registry and try to duplicate Cygwin's logic. I
tried this but gave up on it--life's too short for that. Or you try to adapt
the Cygwin C code. Or try to access the functions in cygwin.dll. Whatever.

On an NT system without Cygwin, or on a Unix system, then there is no
obvious mapping and (as far I can see) no need for one. Why do you want to
use one style of path in your config files? Surely it would be better to use
paths that are appropriate for the system, then process them with Python's
os module.

--
Mark Hadfield "Ka puwaha te tai nei, Hoea tatou"
m.********@niwa.co.nz
National Institute for Water and Atmospheric Research (NIWA)

Jul 18 '05 #3
On Thu, 2003-07-10 at 13:44, Noah wrote:
Does anyone have a function to convert back and forth between
NT style paths and POSIX style? It seems trivial, but
I want to make sure I don't overlook some obscure detail.
Is it a simple matter of translating / and \ characters?

FYI, I need a Python function that does what cygpath does so that
I can run a script on either NT or UNIX or Cygwin.
I want my config files use one style of path.


Just use POSIX paths and let the Python library sort it out. It works.
If you really need to do the conversions yourself, take a look at the
os.path module.

--
Cliff Wells, Software Engineer
Logiplex Corporation (www.logiplex.net)
(503) 978-6726 (800) 735-0555
Jul 18 '05 #4
N.K
os.path.join is what you are looking for, i beleive

eg: appendedpath = os.path.join(dir1,filename)

Regards
Nirmal

no**@noah.org (Noah) wrote in message news:<c9**************************@posting.google. com>...
Does anyone have a function to convert back and forth between
NT style paths and POSIX style? It seems trivial, but
I want to make sure I don't overlook some obscure detail.
Is it a simple matter of translating / and \ characters?

FYI, I need a Python function that does what cygpath does so that
I can run a script on either NT or UNIX or Cygwin.
I want my config files use one style of path.

Yours,
Noah

Jul 18 '05 #5
Peter Hansen <pe***@engcorp.com> wrote in message news:<3F***************@engcorp.com>...
You can use forward slashes in paths under Win32, except at the
command prompt.

Even if you switch to use all forward slashes, however, what do
you plan to do about drive letters? There is no obvious mapping
to anything under POSIX, I think. Are you planning on disallowing
paths that go anywhere but the current drive under NT?
-Peter


I had forgotten that NT supports forward slashes.
My only concern is that some of the config file values are
set programatically and I use os.path.join everywhere, so if the
config file is modified when running under Windows then the paths
will get \ separators and that will confuse the UNIX side.
I think I will still need something to ensure that the paths
are consistent... Hmmm... I wonder how evil it would be to simply set
os.sep = '/' when I initialize my application. I wonder if I will be
angering the dark lords of Microsoft by doing this.

I was going to simply remove the drive letter, so, yes, that would
disallow paths other than the curent drive. I might also map the drive
letters to a point on the POSIX path or I might do it Cygwin style
where C: becomes /cygdrive/c/.
Jul 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
3785
by: | last post by:
Hello, We upgraded to Windows Small Business Server 2003 It seems that there is something changed with the asp INCLUDE statement. here is my code: <!--#include file="../_includes/common.asp"...
1
2075
by: vck_82 | last post by:
HI Does any body know how to convert windows style path to posix style path. I need this because i am developing a windows application which actually starts an exe which is developed in unix....
5
4094
by: Andy Sutorius | last post by:
Hi, I am attempting to convert this vb function to csharp but I am getting stuck on the if statement dt.Rows(iLoop)("FAQCategoryID")). The compiler says "method name expected" and underlines...
16
2615
by: NetPointer | last post by:
How to convert following in to VB.NET ??? specifically the constant...es_number. const int ES_NUMBER = 0x2000; protected override System.Windows.Forms.CreateParams CreateParams { get {...
2
5997
by: anand.ba | last post by:
Hi all I need to find equivalent windows libraries for the following unix ones. #include <sys/prctl.h> #include <sys/ioctl.h> #include <unistd.h>
25
1925
by: guisep4 | last post by:
I have unusual "problem" with naming local variable "index". It all began when I added -Wshadow to gcc commandline. The code is like this: #include <string.h> int foo(void) { int index; ...
55
2718
by: aarklon | last post by:
Hi all, I was going through the book "C Elements of style" by steve oualline. in this book many guidelines are given. the following were seen in the book as rules 1) while(1) is preferred...
9
1986
by: tdahsu | last post by:
All, I have the following code: for fileTarget in dircache.listdir("directory"): (dirName, fileName) = os.path.split(fileTarget) f = open(fileTarget).readlines() copying = False for i in...
23
3306
by: asit | last post by:
what is the difference between portable C, posix C and windows C ???
0
7260
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
1
7099
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7525
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5685
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5086
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4746
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3222
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1594
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
799
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.