473,386 Members | 1,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Full splitting of a file's pathname

I know about os.path.split(), but Is there any standard function for
"fully" splitting a file's pathname? A function that is the opposite of
the os.path.join() function? For example:
>>ret = myster_function(./foo/bar/moo/lar/myfile.txt)
print ret
['.', 'foo', 'bar', 'moo', 'lar', 'myfile.txt']

In the meanwhile, I'll do this by hand. I'm just curious if there is a
standard way to do this.

Jul 10 '06 #1
3 1363
I don't know if it's "standard," but why not just:

dir = './foo/bar/moo/lar/myfile.txt'
dir.split('/')

['.', 'foo', 'bar', 'moo', 'lar', 'myfile.txt']

rd

Jul 10 '06 #2

tac-tics wrote:
I know about os.path.split(), but Is there any standard function for
"fully" splitting a file's pathname? A function that is the opposite of
the os.path.join() function? For example:
>ret = myster_function(./foo/bar/moo/lar/myfile.txt)
print ret
['.', 'foo', 'bar', 'moo', 'lar', 'myfile.txt']

In the meanwhile, I'll do this by hand. I'm just curious if there is a
standard way to do this.
Simple function using os.path.split (so it should be fairly
compatible):

def split(path):
h,t = os.path.split(path)
if h == path:
return [h]
else:
return split(h) + [t]

You could throw in os.path.splitdrive and os.path.splitunc, if you
wanted to be really complete.

Iain

Jul 10 '06 #3
BartlebyScrivener wrote:
I don't know if it's "standard," but why not just:

dir = './foo/bar/moo/lar/myfile.txt'
dir.split('/')

['.', 'foo', 'bar', 'moo', 'lar', 'myfile.txt']

rd
There's also os.path.sep, from the docs: "The character used by the
operating system to separate pathname components."
But a recursive function like the one Iain King posted is likely the
best way to go.

~Simon

Jul 11 '06 #4

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

Similar topics

3
by: Jason Heyes | last post by:
I want to open a file with a known location and process its contents. The contents are to be treated as a list of pathnames. Each pathname is an absolute or relative pathname in the following...
2
by: Susan Baker | last post by:
Hi, I am (trying) to compile some code I downloaded from the internet. The sources contain references to header files - using the form : #include <pathname/file> If I change the form to...
5
by: roland.groenvynck | last post by:
I try to build my first web form application with C#. I want to program the downloading of a file to the client . Therefore I can use WebClient.DownloadFile (url, filepath ); I would like that...
11
by: rh00667 | last post by:
hi all, i'm confused now. how i can get the full path of an application? if myapp is in a directory which belongs to PATH, argv gives me the first token of cmd line, and not the real path of...
1
by: marathoner | last post by:
When I use the FileUpLoadControl to select a file, I can only retrieve the filename that was selected. I want to know how to retrieve the full pathname of the filename selected. Marathoner
8
by: andrew.jefferies | last post by:
Hi, I'm trying to write a simple log parsing program. I noticed that it isn't reading my log file to the end. My log is around 200,000 lines but it is stopping at line 26,428. I checked that...
2
by: Plum Bob | last post by:
Hi - I use a simple JS function to open popups on my site: <script language="javascript"> <!-- var pathname; function openit(pathname) { newWindow = window.open(pathname, 'wndow1',...
40
by: Phlip | last post by:
Scott Lurndal wrote: Would it also cause a problem if your file descriptors go "around the horn", and exceed some platform-specific limit, such as 0x80000000? They would "go negative" when...
65
by: Hongyu | last post by:
Dear all: I am trying to write to a file with full directory name and file name specified (./outdir/mytestout.txt where . is the current directory) in C programming language and under Unix, but...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.