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代码,实现遍历该路径下的所有文 件

>>>

相关推荐
從南走到北1 分钟前
JAVA国际版二手车交易二手车市场系统源码支持Android+IOS+H5+APP
android·java·ios
江上清风山间明月7 分钟前
Android 系统中进程和线程的区别
android·python·线程·进程
Kuo-Teng9 分钟前
LeetCode 19: Remove Nth Node From End of List
java·数据结构·算法·leetcode·链表·职场和发展·list
北i11 分钟前
TiDB 关联子查询去关联优化实战案例与原理深度解析
java·数据库·sql·tidb
Kuo-Teng12 分钟前
LeetCode 21: Merge Two Sorted Lists
java·算法·leetcode·链表·职场和发展
mit6.82414 分钟前
[LivePortrait] docs | Gradio用户界面
python
我命由我1234518 分钟前
Java 开发 - 粘包处理器 - 基于消息头 + 消息体(魔数验证、长度验证)
java·网络·后端·网络协议·java-ee·intellij-idea·intellij idea
2301_8003997224 分钟前
stm32 printf重定向到USART
java·stm32·算法
bagadesu28 分钟前
15.<Spring Boot 日志>
java·后端
小龙报30 分钟前
《嵌入式成长系列之51单片机 --- Keil5创建工程》
c语言·开发语言·c++·单片机·嵌入式硬件·51单片机·学习方法