OS module functions "Python" for directory Processing

Source: Internet
Author: User

In Python, you can use the Os.listdir () function to get the contents of the specified directory. Its prototype is shown below. os.listdir (path)The parameters have the following meanings. Path to get the paths to the content directory. The following instance obtains the contents of the current directory. >>> Import os >>> os.listdir (OS.GETCWD ()) Get the contents of the current directory [' Dde.pyd ', ' license.txt ', ' Pythonwin.exe ', ' s Cintilla.dll ', ' win32ui.pyd ', ' win32uiole.pyd ', ' Pywin '] How to create a directory in a Python programming language you can use the Os.mkdir () function to create a directory in Python. Its prototype is shown below. os.mkdir (path)Its parameter meaning is. path where you want to create the directory. The following instance creates the Temp directory under the E:\book directory. >>> Import os >>> os.mkdir (' e:\\book\\temp ') use Os.mkdir to create a directory delete directory in Python you can use the Os.rmdir () function to delete a directory. Its prototype is shown below. os.rmdir (path)The parameters have the following meanings. Path of the directory to be deleted by path. The following instance deletes the E:\book\temp directory. >>> Import os >>> os.rmdir (' e:\\book\\temp ') to remove a directory, it is important to note that directories that are deleted using Os.rmdir must be empty directories or the function will fail. The above is a description of how the Python programming language obtains content from the directory, creates a directory, and how to remove the contents of the directory in the Python programming language.

OS module functions "Python" for directory Processing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.