import os
print(os.path.join('usr', 'local', 'bin'))
print(os.getcwd())
print(os.path.abspath('.'))
print(os.path.abspath('./Os.py'))
print(os.path.isabs('.'))
# os.path.relpath(path, start)将返回从 start 路径到 path 的相对路径的字符串。
# 如果没有提供 start,就使用当前工作目录作为开始路径
print(os.path.relpath('usr/', 'usr/local/bin')) # ../..
print(os.path.dirname('usr/local/bin')) # usr/local
print(os.path.basename('usr/local/bin')) # bin
# 分割符
print('/usr/local/bin'.split(os.path.sep)) # ['', 'usr', 'local', 'bin']
# 文件的字节数
print(os.path.getsize('./Os.py'))
# 返回文件名字符串的列表
print(os.listdir(os.getcwd()))
cwd = os.getcwd()
for fileName in os.listdir(os.getcwd()):
file_dir = os.path.join(cwd, fileName)
if os.path.isfile(file_dir):
print(fileName, ' ', os.path.getsize(os.path.join(cwd, fileName)))
# 检查路径有效性
print(os.path.exists('/usr/local/bin'))
print(os.path.isfile('/usr/local/bin'))
print(os.path.isdir('/usr/local/bin'))