Python OS simple file / directory operations

Python OS simple file / directory operations

The Python OS module contains a directory of files and processing method, referred to herein include a few

Incomplete parameter list

Delete, create and other operations

  • os.mkdir(path): Create a file called the working directory pathfolder
  • os.remove(path): Delete the path to paththe file, if the file does not exist or is a folder will be thrownOSError
  • os.rmdir(path): Delete called pathempty file folder, if the folder is not empty is thrownOSError
  • os.removedirs(path): Recursively delete a folder
  • os.rename(src, dst): The specified file / folder ( src) Renamedst

Access operations

  • os.walk(top): Sequentially access a folder topfor all files and directories, and a return value triples, each clip file being accessed addresses, all the sub-clip files being accessed folder ( listtype), the file being accessed folder All files ( listtypes)
  • os.listdir(path): Return pathall of the folders and files directory ( listtype)

Guess you like

Origin www.cnblogs.com/akakw1/p/11782422.html