python common function module file operation os

When the python programming, and often files, directories deal, which is and can become the os module. os module includes general operating system functions, independent of the specific platform. Here are commonly used commands

Os.name 1. - judgment is now practical platform, Windows returns 'nt'; Linux returns 'posix'

With python IDLE test, can directly return a result, if the other third-party editor needs with print (os.name) to output the result, the following examples are the same.

 

 Os.getcwd 2. () - get the current working directory.

 

Os.remove 3. () - delete the specified file

Os.rmdir 4. () - Removes the specified directory

Delete a folder, poor presentation, try their own

Os.mkdir 5. ()- create a directory

Is in the specified directory create a new folder

 

  6.os.makedirs () - recursive directory build

File folders can create multiple subdirectories

 

  7.os.path.isfile () - to determine whether the specified object file

BOOL return value, this is a folder, it is False.

  

 8.os.path.isdir () - determine whether the specified object directory

To keep up with the use of an anti, whether it is a folder

  

 9.os.path.split () - Returns the directory path and file name

  

10. The os.path.getsize () - get the size of the file

This function is to be set to the file, the next test is allowed folder can not be used to get the size of the folder,

Look at the following test to understand, it returns the byte, Byte.

  

11.os.path.join (path, name) - connected directory and filename

This very practical connection path

  

12.os.path.basename (path) - Returns the file name,

Actually it is to find a slash behind the name

  

13.os.path.dirname (path) - Returns the file path

 

Guess you like

Origin www.cnblogs.com/passagain/p/11447413.html