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

how to touch a file

hi

i have a dir that contains directories with names and spaces in between
example

rootdir
| ----> ABC DEF A
| ---> BDD SD N

I wanted to touch a file with the same name as the directories inside
each directory

rootdir
| ----> ABC DEF A
|-------> ABC DEF A-dummy
| ---> BDD SD N
|-------> BDD SD N-dummy

heres the code :
for d in os.walk(rootdir):
(dirpath, dirnames, filenames) = d
for dir in [dirpath]:
if not os.path.exists( os.path.join(dir,"-dummy") ):
f = open( os.path.join(dir,"-dummy") ,
"w").write("")

but i got only "-dummy" as the filename in each directory

How can i deal with spaces in this case? or is there some wrong things
i do in the code?
thanks for any help.

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

i have a dir that contains directories with names and spaces in between
example

rootdir
| ----> ABC DEF A
| ---> BDD SD N

I wanted to touch a file with the same name as the directories inside
each directory

rootdir
| ----> ABC DEF A
|-------> ABC DEF A-dummy
| ---> BDD SD N
|-------> BDD SD N-dummy

heres the code :
for d in os.walk(rootdir):
(dirpath, dirnames, filenames) = d
for dir in [dirpath]:
if not os.path.exists( os.path.join(dir,"-dummy") ):
f = open( os.path.join(dir,"-dummy") ,
"w").write("")

but i got only "-dummy" as the filename in each directory

How can i deal with spaces in this case? or is there some wrong things
i do in the code?


os.path.join joins paths with the proper OS-dependend separator. So

os.path.join("a", "b", "c")

becomes

a/b/c

under unix. Naturally, joining dir and "-dummy" produces "<dir>/-dummy" -
which is what you see.

Instead, do something like this:

for d in os.walk(rootdir):
(dirpath, dirnames, filenames) = d
for dir in [dirpath]:
fname = os.path.basename(dir) + "-dummy"
if not os.path.exists( os.path.join(dir,fname) ):
f = open( os.path.join(dir,fname) ,
"w").write("")
Diez

Apr 6 '06 #2

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

Similar topics

5
by: pekka niiranen | last post by:
Does anybody know Python recipe for changing the date of the directory or files in W2K to current date and time? In UNIX shell command "touch" does it. -pekka-
2
by: Robert May | last post by:
I have an application that processes text strings using information in a file. I want to deploy this app using no-touch deployment. The config files and everything else are deployed just fine,...
3
by: Marek | last post by:
Hi there, my WinForm application has to be installed in "no-touch-deployment" mode, so users can run it from the web. I need to read application's .config file but it does not work in ...
10
by: Kenneth McDonald | last post by:
I could've sworn python had such a command, but now I can't find it... I'm looking for an easy way to perform a UNIX-style "touch", to update the modification time of a file without actually...
4
by: James | last post by:
I have a VB windows forms application that accesses a Microsoft Access database that has been secured using user-level security. The application is being deployed using No-Touch deployment. The...
1
by: James | last post by:
I have a VB windows forms application that accesses a Microsoft Access database that has been secured using user-level security. The application is being deployed using No-Touch deployment. The...
25
by: Michelle | last post by:
Hi, I am new it vb.net and am looking at writing for touch screens as one of my clients wants their application written for touch screens. I'm sure someone that done this before. Are there links...
1
by: =?Utf-8?B?dmNs?= | last post by:
Short version: IE7 and .NET Framework 2.0 breaks no touch deployment for .NET 1.1 applications. IE6 and .NET Framework 1.1 + 2.0 works fine. IE7 with .NET Framework 1.1 only is fine, once we add...
2
by: Chuck Anderson | last post by:
I've got a script that "syncs" files from my working hard drive (Windows XP) to a backup drive based on filesize and filemtime. It's never had problems at the DST switch before, but since...
8
by: Nikhil | last post by:
what are the simple ways? I could think of os.open(), os.exec(touch file) are there any simpler methods?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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,...
0
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
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
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,...

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.