os模块
os.name
导入的操作系统相关模块的名称
os.uname()
*nix支持
sys.platform
print(sys.platform)
打印结果:
win32
os.listdir(path=’.’):返回目录内容列表,不递归
等同于list(p3.parents[4])
返回一个list,包含给定path 目录下所有条目的名字。该list是任意顺序,不包括特殊条目’.‘以及’…’,即使它们存在于目录中。
p3 = Path('E:/test/1/2/3/a.txt')
print(os.listdir(p3.parents[4]))
打印结果:
['$RECYCLE.BIN', '2345Downloads', '360', '360Downloads', '360SoftMgrGame', '360软件下载', '360驱动大师目录', 'Acrobat-7.0-PRO-CN', 'Adobe', 'CentOS 6.9', 'CentOS 7.6-ok', 'CentOS 7.6pyenv', 'CentOS 7.6python3.7', 'CentOS光盘', 'CloudMusic', 'kms', 'KwDownload', 'LaoMaoTao', 'Linux学习视频', 'MailMasterData', 'PDF转word', 'Pycharm', 'PycharmProjects', 'Python笔记', 'qq', 'scode文本编辑', 'shell日志', 'System Volume Information', 'test', 'VM安装包', 'Windows 10 x64', 'Windows 7---ok', 'WPS Office', 'Xmanager Enterprise 5 Build 0576', '日记', '暴风影音', '测磁盘速度', '浏览器下载', '鹏保宝']
os.stat(path, *, dir_fd=None, follow_symlinks=True)
获取文件或文件描述符的状态。在给定的路径上执行相同的stat()系统调用。path可以被指定为一个字符串或一个打开的文件描述符。
print(os.stat(p3))
打印结果:
os.stat_result(st_mode=33206, st_ino=4222124650680161, st_dev=83635370, st_nlink=1, st_uid=0, st_gid=0, st_size=0, st_atime=1556808770, st_mtime=1556808770, st_ctime=1556803373)
os.chmod(path, mode, *, dir_fd=None, follow_symlinks=True)
将路径的模式更改为数字模式。mode可以采用以下值之一(如stat模块中定义的)或它们的按位或运算组合:
print(os.chmod(p3,0o666))
os.chown(path, uid, gid, *, dir_fd=None, follow_symlinks=True)
将path的所有者和组标识更改为数字uid和gid