Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to delete multiple directories in python

Shulou Source: shulou.com Published: 2022-05-31 11:12:34 09月21日 Update

This article introduces the knowledge of "how to delete multiple directories in python". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Specific operation methods:

1. Find the python program in the start menu of win system.

2. Find and open the idle tool program in the python program directory.

3. Click "File" in the upper left corner of the idle tool and select "New File" to create a new shell script.

4. Enter the following instructions in the shell script to import the os module.

Import os # Import os module

5. Finally, you can recursively delete multiple directories through the following instruction.

Os.removedirs (path) # path refers to the directory path to be removed

Related operation instructions:

Os.getcwd () # gets the current working directory

Os.path.getsize (file name) # View the size of the specified file

Os.listdir () # returns all file and directory names under the specified directory

Related examples:

#! / usr/bin/python

#-*-coding: UTF-8-*-

Import os, sys

# list directories

The print "directory is:% s"% os.listdir (os.getcwd ())

# remove

Os.removedirs ("/ test")

# list the removed directories

After print "is removed, the directory is% s:"% os.listdir (os.getcwd ())

This is the end of "how to delete multiple directories in python". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Directories multiple instructions files programs contents tools more modules knowledge scripts practical successful learning next dilemma size instance actual upper left corner situation Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Redmi NVidia MySQL Xiaomi