18 operating system/OS. Path

Source: Internet
Author: User
Common functions for file/directory in the OS Module

 

Function Name Usage
Getcwd () Back to current working directory
Chdir (PATH) Change working directory
Listdir (Path = '.') List the file names in the specified directory ('.' indicates the current directory, '..' indicates the upper-level directory)
Mkdir (PATH) Create a single-level directory. If this directory already exists, an exception is thrown.
Makedirs (PATH) Recursively create a multi-level directory. if an exception is thrown, note that the values of 'e: \ A \ B 'and 'e: \ A \ C' do not conflict.
Remove (PATH) Delete an object
Rmdir (PATH) Deletes a single-level directory. If the directory is not empty, an exception is thrown.
Removedirs (PATH) Recursively delete directories, from subdirectories to parent directories, and try to delete directories layer by layer. If the directory is not empty, an exception is thrown.
Rename (old, new) Rename the old file to new
System (command) Run the shell command of the system
Walk (top) Traverse all the subdirectories in the top path and return a triple: (path, [including Directory], [including files]) [For specific implementation solutions, see homework _ ^ after lecture 30th]
The following are definitions commonly used to support path operations.
OS. curdir Indicates the current directory ('.')
OS. pardir Indicates the upper-level directory ('..')
OS. SEP Specify the path separator for the output Operating System ('\' For Win and '/' for Linux '/')
OS. linesep The row Terminator used by the current platform ('\ r \ n' in win and' \ n' in Linux ')
OS. Name Indicates the operating system currently in use (including 'posix', 'nt ', 'mac', 'oss2', 'ce', and 'java ')



Common Path functions in the OS. Path Module

 

Function Name Usage
Basename (PATH) Remove the directory path and return the file name separately.
Dirname (PATH) Remove the file name and return the directory path separately.
Join (path1 [, path2 [,...]) Combine the parts of path1 and path2 into a path name.
Split (PATH) Splits the file name and path and returns the (f_path, f_name) tuples. If the directory is fully used, it also separates the last directory as the file name and does not determine whether the file or directory exists.
Splitext (PATH) Separates the file name and extension, and returns the (f_name, f_extension) tuples.
Getsize (file) Returns the size of the specified file, in bytes.
Getatime (file) Returns the last access time of the specified file (floating point number of seconds, which can be converted by the gmtime () or localtime () function of the time module)
Getctime (file) Returns the creation time of the specified file (floating point number of seconds, which can be converted by the gmtime () or localtime () function of the time module)
Getmtime (file) Returns the latest modification time of the specified file (floating point number of seconds, which can be converted by the gmtime () or localtime () function of the time module)
The following functions return true or false.
Exists (PATH) Determines whether a specified path (directory or file) exists
Isabs (PATH) Determines whether the specified path is an absolute path.
Isdir (PATH) Determines whether the specified path exists and is a directory
Isfile (PATH) Determines whether a specified path exists and is a file
Islink (PATH) Determines whether a specified path exists and is a symbolic link.
Ismount (PATH) Determines whether the specified path exists and is a mount point
Samefile (path1, paht2) Determine whether the paths path1 and path2 point to the same file

 

18 operating system/OS. Path)

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.