473,569 Members | 3,040 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1373
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(p ath)
if h == path:
return [h]
else:
return split(h) + [t]

You could throw in os.path.splitdr ive and os.path.splitun c, if you
wanted to be really complete.

Iain

Jul 10 '06 #3
BartlebyScriven er 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
1393
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 sense: - the current directory is the directory of the opened file - the root directory is the program directory (i.e., working directory of the...
2
2997
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 this: #include "pathname/file"
5
1682
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 the user is able to select the directory(on his machine) with a kind of a control ? How can I do that? many thanks for helping me
11
8259
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 the executed program. so if i write anywhere:
1
1599
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
2143
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 line and there aren't any special characters. This is the file reading code segment that I'm using: sysFile=open(sysFilename,'r')
2
2095
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', 'resizable=yes,scrollbars=yes'); } // -->
40
2446
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 expressed as signed integers... Does some relatively standard .h file define a good constant there?
65
5036
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 got errors of Failed to open file ./outdir/mytestout.txt. Below is the code: #include <stdio.h>
0
7703
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...
0
7619
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...
0
7930
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8138
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...
0
7983
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6290
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...
1
5514
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...
0
3662
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.