473,395 Members | 1,738 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,395 software developers and data experts.

How remove directories with the content in the platform independentway?

How remove directories with the content in the platform independent way?
Is the API for that?

Thx, A.
Jul 19 '05 #1
5 1359
Look at the os and os.path modules.

http://docs.python.org/lib/module-os.html
http://docs.python.org/lib/module-os.path.html

On Tuesday 26 April 2005 07:27 pm, so sayeth Andy Leszczynski:
How remove directories with the content in the platform independent way?
Is the API for that?

Thx, A.


--
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/
Jul 19 '05 #2
James Stroud wrote:
Look at the os and os.path modules.

http://docs.python.org/lib/module-os.html
http://docs.python.org/lib/module-os.path.html

On Tuesday 26 April 2005 07:27 pm, so sayeth Andy Leszczynski:
How remove directories with the content in the platform independent way?
Is the API for that?

Thx, A.


It is not clear if rmdir would remove the non-empty dir ...

Jul 19 '05 #3
Andy Leszczynski wrote:
James Stroud wrote:
Look at the os and os.path modules.

http://docs.python.org/lib/module-os.html
http://docs.python.org/lib/module-os.path.html

On Tuesday 26 April 2005 07:27 pm, so sayeth Andy Leszczynski:
How remove directories with the content in the platform independent way?
Is the API for that?

Thx, A.


It is not clear if rmdir would remove the non-empty dir ...

never min, I found this in that doc :-)

# Delete everything reachable from the directory named in 'top',
# assuming there are no symbolic links.
# CAUTION: This is dangerous! For example, if top == '/', it
# could delete all your disk files.
import os
for root, dirs, files in os.walk(top, topdown=False):
for name in files:
os.remove(os.path.join(root, name))
for name in dirs:
os.rmdir(os.path.join(root, name))

Jul 19 '05 #4
There's also the shutil module, which is platform independant.

http://docs.python.org/lib/module-shutil.html

....see the rmtree function

Jul 19 '05 #5
Jason Mobarak wrote:
There's also the shutil module, which is platform independant.

http://docs.python.org/lib/module-shutil.html

...see the rmtree function

Thanks, this is what I was looking for.

A.
Jul 19 '05 #6

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

Similar topics

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)
3
by: dave | last post by:
I am using vs.net 2003 on windows xp. After clicking on a project within my solution and selecting create new folder vs.net responds back with , the "directory already exists". If i look at the...
2
by: hokieghal99 | last post by:
I wish to place all files and directories that are within a user defined path (on a Linux x86 PC) into some type of array and then examine those items for the existence of certain charaters such as...
3
by: Arpi Jakab | last post by:
I have a main project that depends on projects A and B. The main project's additional include directories list is: ...\ProjectA\Dist\Include ...\ProjectB\Dist\Include Each of the include...
1
by: Lloyd Dupont | last post by:
I have VS.NET 2005 standart edition. Before installing it I had installed VC++ express. I did modify some directory variable in VC++ express to have some project working. Now VS.NET is all...
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...
63
by: David Mathog | last post by:
There have been a series of questions about directory operations, all of which have been answered with "there is no portable way to do this". This raises the perfectly reasonable question, why,...
25
by: smarty | last post by:
how to create folders/directories in C. are there any library functions for these?
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?
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
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
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
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...

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.