Python uses the Os.listdir () function to get the contents of a directory

Source: Internet
Author: User

Excerpt from: http://it.100xuexi.com/view/otdetail/20130423/057606dc-7ad1-47e4-8ea6-0cf75f514837.html

1. In Python, you can use the Os.listdir () function to get the contents of the specified directory. Its prototype is shown below.
Path to get the path to the content directory, the following instance obtains the contents of the current directory:
Import OS   >>> Os.listdir (OS.GETCWD ())  
[' Dde.pyd ', ' license.txt ', ' Pythonwin.exe ', ' scintilla.dll ', ' win32ui.pyd ', ' win32uiole.pyd ', ' Pywin ']
2. In Python, you can use the Os.mkdir () function to create a directory. Its prototype is shown below.
Path to create directory paths, the following instances will create the temp directory under the E:\book directory.
Import OS   >>> os.mkdir ('e:\\book\\temp'
3. In Python, you can use the Os.rmdir () function to delete a directory. Its prototype is shown below.
Path to the directory to delete, the following instance deletes the E:\book\temp directory.
Import OS   >>> os.rmdir ('e:\\book\\temp')   
NOTE: Deleting a table of contents requires that directories deleted using Os.rmdir must be empty directories, or the function will fail.

Python uses the Os.listdir () function to get the contents of a directory

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.