473,406 Members | 2,620 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,406 software developers and data experts.

How to work with directories and files with spaces

hi

I am working in unix and i have some directories names with spaces
eg ABC DEF A
how can i work effectively with spaces in directory/file names in
python?

sometimes when i do os.path.join(dir_with_spaces,"-somestring" ) , it
gives me "-somestring" as the name only...without ABC DEF A
it should give me ABC DEF A-somestring as the directory name

thanks

Apr 6 '06 #1
2 7007
s9************@yahoo.com wrote:
hi

I am working in unix and i have some directories names with spaces
eg ABC DEF A
how can i work effectively with spaces in directory/file names in
python?


Like you can do with unix:

michele:~$ echo "Michele" > my\ name
michele:~$ python
Python 2.3.5 (#2, May 4 2005, 08:51:39)
[GCC 3.3.5 (Debian 1:3.3.5-12)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
open("my name") <open file 'my name', mode 'r' at 0x401e3ba0> import os
os.system("cat my\ name") Michele
0 os.system("cat 'my name'")

Michele
0

Bye,
Michele :)
Apr 6 '06 #2
s9************@yahoo.com wrote:
hi

I am working in unix and i have some directories names with spaces
eg ABC DEF A
how can i work effectively with spaces in directory/file names in
python?

sometimes when i do os.path.join(dir_with_spaces,"-somestring" ) , it
gives me "-somestring" as the name only...without ABC DEF A
it should give me ABC DEF A-somestring as the directory name

thanks


The spaces aren't the problem AND you are misreading what
os.path.join does:

join( path1[, path2[, ...]])

Joins one or more path components intelligently. If any component
is an absolute path, all previous components are thrown away, and
joining continues. The return value is the concatenation of path1,
and optionally path2, etc., with exactly one directory separator
(os.sep) inserted between components, unless path2 is empty. Note
that on windows, since there is a current directory for each drive,
os.path.join("c:", "foo") represents a path relative to the current
directory on drive C: (c:foo), not c:\\foo.

dir_with_spaces="ABC DEF A"
import os
os.path.join(dir_with_spaces, '-somestring') 'ABC DEF A\\-somestring'


To do what you wanted (based on your example) I would do:

import os
fullpath="%s%s" % (dir_with_spaces, '-somestring')

-Larry Bates
Apr 6 '06 #3

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

Similar topics

1
by: Reed Law | last post by:
I have the exact same data in two arrays, but only the array created like so will work: $spaw_imglibs = array( array( 'value' => '/youth/pics/Member pics/', 'text' => 'Member pics', ),...
5
by: Tum | last post by:
Hi folks, I've been trying to make a decision and it's driving me crazy. Is a directory a file or is a directory NOT a file but a node? Should I have A)
4
by: Grant Harmeyer | last post by:
How would I set up an httpHandler so that it would only apply to certain child directories of the application? I.E: <httpHandlers> <add verb="*" path="/files/*/*/*/*.aspx"...
5
by: rbt | last post by:
What is the most efficient way to recursively remove files and directories? Currently, I'm using os.walk() to unlink any files present, then I call os.walk() again with the topdown=False option...
2
by: Angelo Cook | last post by:
how do you prevent the publishing of virtual directories in VS 2005. I have been using VS2003 and developing websites for years. I have been using virtual directories for images, icons, styles...
4
by: rn5a | last post by:
I have a ListBox which should list all the files & directories that exist in a particular directory. The problem is I can get the ListBox to list either all the files or all the directories but not...
1
by: rn5a | last post by:
A ListBox lists all the folders & files existing in a directory named 'MyDir' on the server. Assume that the ListBox lists 2 directories - 'Dir1' & 'Dir2' i.e. these 2 directories reside in the...
4
by: Jason Teagle | last post by:
I'm not sure which is the correct group to post this to, if either, so apologies for the crosspost and if it's OT. I have a Visual Studio.NET 2002-compiled solution that originated at work. At...
1
by: =?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?= | last post by:
I get the above error in some of the ASP.NET web applications on a server, and I need some help figuring out how to deal with it. This is a rather long post, and I hope I have enough details that...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...
0
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...
0
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...
0
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,...
0
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...

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.