473,666 Members | 2,208 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

file delimiter in dependency of os

Hallo,

I have pathes with different file delimiters
e.g.
/root/dir\mydir/myfile
C:\xxx/hh\gggg/myfile

How can I change the mistaken file delimiters in dependency of the
used os (win or unix) effectively?
unix: /root/dir\mydir --> /root/dir/mydir
win: C:\xxx/hh\gggg/myfile --> C:\xxx\hh\gggg\ myfile

Thanks for your hints Thomas
Jul 18 '05 #1
2 3231
Thomas Steffen wrote:
Hallo,

I have pathes with different file delimiters
e.g.
/root/dir\mydir/myfile
C:\xxx/hh\gggg/myfile

How can I change the mistaken file delimiters in dependency of the
used os (win or unix) effectively?
unix: /root/dir\mydir --> /root/dir/mydir
win: C:\xxx/hh\gggg/myfile --> C:\xxx\hh\gggg\ myfile

Thanks for your hints Thomas


Note that backslashes are only needed for the conventional user experience,
Windows is happy with "/", too. Have a look at os.path.normcas e() which
should meet your needs if you are consistently using forward slashes in
your application. Otherwise the following tiny module might do (untested):

<plat.py>
import os
if os.name == "posix":
def normslash(path) :
return path.replace("\ \", "/")
elif os.name == "nt":
def normslash(path) :
return path.replace("/", "\\")
else:
raise Exception("OS not supported: %s" % os.name")
</plat.py>

usage:

import plat
path = plat.normslash( path)

By the way, if you are building paths like so:

path = folder + "/" + filename

Use os.path.join() instead. It will automatically select the right separator
for you.

Peter

Jul 18 '05 #2
Peter Otten wrote:

Thomas Steffen wrote:
Hallo,

I have pathes with different file delimiters
e.g.
/root/dir\mydir/myfile
C:\xxx/hh\gggg/myfile

How can I change the mistaken file delimiters in dependency of the
used os (win or unix) effectively?
unix: /root/dir\mydir --> /root/dir/mydir
win: C:\xxx/hh\gggg/myfile --> C:\xxx\hh\gggg\ myfile

Thanks for your hints Thomas


Note that backslashes are only needed for the conventional user experience,
Windows is happy with "/", too. Have a look at os.path.normcas e() which


Or, to be more practical, backslashes are needed for commands that are
passed to the MS-DOS shell with os.system() and friends. Any other
way of getting the paths to the OS should work with forward slashes.

-Peter
Jul 18 '05 #3

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

Similar topics

2
11149
by: nospam | last post by:
If I had a text file with the following two columns: key1 value1 key2 value2 key3 value3 How would I read in this file and create an associative array?
2
4364
by: Dave Stone | last post by:
Does anyone know if it's possible to use the wizard or DTS Designer to accept a source file with the following simplified format: <field1label>: <record1field1value> <field2label>: <record1field2value> - - - - - - - <fieldNlabel>: <record1fieldNvalue> <field1label>: <record2field1value> <field2label>: <record2field2value>
11
3072
by: Skc | last post by:
I have a .txt which has been exported as a .csv from an external source. What i need to do is to import this into SQL2000 (into a table) but I need to do special things on the data: 1. I need to look for the first three chars and import rows into separate tables. E.g. if the first three chars begin with CCC, then this row goes into the CCC_table, if it is TTT then into the TTT_table etc... 2. Once I have my tables built up, I need to do...
6
1772
by: Greg Collins [MVP] | last post by:
For background, please refer to my original thread: http://groups.google.com/groups?selm=efe5w7tYEHA.3112%40tk2msftngp13.phx.gbl I've thought of a potential way around the issue, but I'm new to ASP.NET and C# and need the expertese of individuals with more experience in these languages than I have. I may be completely off target as I thought this up very early in the morning. Here's the process as I see it: 1. InfoPath saves out the...
8
14580
by: asrs63 | last post by:
Hi, I am a newbee and have a comma seperated flat-file and a DTD. I need to write a C# program which will read the text file and convert it to a XML file as per the the definition in the DTD. I am not able to find anything help-ful and don't know how to begin to code. Can anyone please help me? Thanks in advance
5
2548
by: rjl444 | last post by:
My app has a lot of properties, instead of placing the values in webconfig file (because I have tons), I would like to place these in it's own file. What is the best way of using an independant file? Should I consider resource file? thanks.
2
1668
by: removethispamfilter | last post by:
Hi Im working in a company where windows systems are set up for different "countries". When setting up the "import from csv file" the decimal separator is set up to "," (the thousands separator is not set) and the text delimiter is set to " when users having a windows not based upon this standard in numbers ( in UK it is "." as decimal separator), the access takes the definition
19
5376
by: Lee Crabtree | last post by:
Is there a class in the framework that allows me read text from a file in an unbuffered manner? That is, I'd like to be able to read lines in the same manner as StreamReader.ReadLine(), but I also need to be able to accurately get the position in the file of that line. Since StreamReader and FileStream both buffer data, you can't equate the BaseStream.Position with the data you're reading from the stream. Lee Crabtree
4
2119
by: MikeJ | last post by:
make a While loop ofs = TextFileServer("somefile") string srow while (ofs=false) { srow=ofs.getRow(); Console.Writeline(srow); }
0
8443
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8356
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8781
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7385
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6192
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5663
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4366
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2769
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 we have to send another system
2
1772
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.