Skip to content

Latest commit

 

History

History
25 lines (22 loc) · 2.97 KB

os.md

File metadata and controls

25 lines (22 loc) · 2.97 KB

os

import os
Method Description Usage
os.getcwd() return the present working directory os.getcwd()
os.chdir(path) change the working directory to os.chdir('~/python')
os.access(path, mode) return True/False if can operate in os.access('~/python', 'F_OK')
'F_OK': check the path exists
'R_OK': check read permission
'W_OK': check write permission
'X_OK': check execute permission
'R_OK': check read permission
os.listdir(path) return a list of files and directories in the or the present working directory os.listdir()
os.mkdir(path, mode) create a directory on the given with os.mkdir('~/python/newdir', '0777')
os.makedirs(path, mode) same as 'mkdir -r'; create a directory on the given and subdirectories with os.makedirs('~/python/another/subdir'
os.remove(path) remove the given file os.remove('~/python/test.temp')
os.unlink(path) remove the given file os.unlink('~/python/test.temp')
os.rmdir(path) remove the given directory os.rmdir('~/python/another/subdir')
os.removedirs(path) same as 'rmdir -r'; remove a directory on the given and subdirectories os.rmdir('~/python/another/subdir')
os.rename(src, dst) same as 'mv'; rename or move the given directory or file os.rename('~/python/newdir', '~/python/newdirectory')
os.renames(src, dst) same as 'mv -r'; rename or move the given directory or file creating directories if needed os.renames('~/python/newdirectory', '~/python/temp/newdirectory')
os.stat(path) get informations of the given directory os.stat('~/python')
os.utime(path, times) change the access time and modified time of the given , if =None then now() os.utime('~/python')
os.walk(top, topdown=True, onerror=None, followlinks=False) loop startswith the given directory and return pathes and directory names os.walk('~/python')
os.getenv(env, failvalue) return the environment variable if successed or failvalue if failed os.getenv('PYTHONPATH', 'Not Found')