python--os和os.path模块

>>> import os

>>> #curdir #获取当前脚本的绝对路径

>>> os.curdir

'.'

>>> import os.path

>>> #获取绝对路径
>>> os.path.abspath(os.curdir)

'C:\\Users\\GUOGUO'

>>> #chdir #修改当前目录
>>> os.chdir("../")

>>> os.path.abspath(os.curdir)

'C:\\Users'
>>> #打印cpu线程
>>> os.cpu_count()

12
>>> #获取当前路径
>>> os.getcwd()

'C:\\Users'
>>> #获取进程编号
>>> os.getpid()

61340
>>> #查看多进程
>>> os.getppid()

62024
>>> #获取系统名称
>>> os.name

'nt'

>>> #文件分割符

>>> os.sep

'\\'

>>> os.listdir()

'All Users', 'Default', 'Default User', 'desktop.ini', 'GUOGUO', 'Public'

>>> #查看当前文件夹所有文件夹名称

>>> os.scandir()

<nt.ScandirIterator object at 0x0000018BAE3A6850>

>>> re = os.scandir()

**>>> os.path

<module 'ntpath' (frozen)>
>>> from os import path**

>>>

>>> path

<module 'ntpath' (frozen)>

>>> dir(path)

'abspath', 'altsep', 'basename', 'commonpath', 'commonprefix', 'curdir', 'defpath', 'devnull', 'dirname', 'exists', 'expanduser', 'expandvars', 'extsep', 'genericpath', 'getatime', 'getctime', 'getmtime', 'getsize', 'isabs', 'isdevdrive', 'isdir', 'isfile', 'isjunction', 'islink', 'ismount', 'join', 'lexists', 'normcase', 'normpath', 'os', 'pardir', 'pathsep', 'realpath', 'relpath', 'samefile', 'sameopenfile', 'samestat', 'sep', 'split', 'splitdrive', 'splitext', 'splitroot', 'stat', 'supports_unicode_filenames', 'sys'

>>>

>>>

>>> path.abspath(".")

'C:\\Users'

>>> path.altsep

'/'

>>> #查找文件名称

>>> f = "C:\\Users"

>>> path.basename(f)

'Users'

>>>

>>> path.exists(f)

True

>>> #'getatime', 'getctime', 'getmtime',文件访问时间,文件创建时间,文件修改时间

>>> #isabs 判断是不是绝对路径 ismount判断是否挂载'

>>> 拼接路径 path.join()

>>>

>>> #面试题 给定一个路径(如: d://),使用python代码,实现遍历该路径下的所有文 件

>>>

相关推荐
m0_734949797 小时前
MySQL如何配置定时清理过期备份文件_find命令与保留周期策略
jvm·数据库·python
t***5447 小时前
Clang 编译器在 Orwell Dev-C++ 中的局限性
开发语言·c++
m0_514520577 小时前
MySQL索引优化后性能没提升_通过EXPLAIN查看索引命中率
jvm·数据库·python
OtIo TALL7 小时前
redis7 for windows的安装教程
java
H Journey7 小时前
Python 国内pip install 安装缓慢
python·pip·install 加速
oy_mail7 小时前
QoS质量配置
开发语言·智能路由器·php
oyzz1207 小时前
PHP操作redis
开发语言·redis·php
uNke DEPH8 小时前
Spring Boot的项目结构
java·spring boot·后端
nashane8 小时前
HarmonyOS 6学习:网络能力变化监听与智能提示——告别流量偷跑,打造贴心网络感知应用
开发语言·php·harmony app
xixingzhe28 小时前
idea启动vue项目
java·vue.js·intellij-idea