Python Calendar Catalog

Source: Internet
Author: User
Tags string format

Automate the boring Stuff study notes 01

The walk () function of the OS module allows you to implement the operation of the catalog, which takes an absolute path string as a required parameter and returns three parameters:

    • Current directory-the current working directory of the program--name (string format)
    • Current directory-the directory that the program is currently in--all sub-folders (list format)
    • Current directory----All Files (list format) under which the program is currently being searched

Suppose you have the following file structure:

The program code is as follows:

Import OS

For FolderName, subfolders, filenames in Os.walk (' c:\\delicious '):
Print (' The current folder is ' + folderName)

For subfolder in subfolders:
Print (' subfolder of ' + FolderName + ': ' + subfolder)
For filename in filenames:
Print (' FILE INSIDE ' + folderName + ': ' + filename ')

Print (")

The program output results are:

The current folder is C:\delicious
subfolder of C:\delicious:cats
subfolder of C:\delicious:walnut
FILE INSIDE C:\delicious:spam.txt

The current folder is C:\delicious\cats
FILE INSIDE C:\delicious\cats:catnames.txt
FILE INSIDE c:\delicious\cats:zophie.jpg

The current folder is C:\delicious\walnut
subfolder of C:\delicious\walnut:waffles

The current folder is C:\delicious\walnut\waffles
FILE INSIDE C:\delicious\walnut\waffles:butter.txt.

Python Calendar Catalog

Related Article

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.