python pathlib2模块(os.path)
from pathlib2 import Path
print(Path.cwd())
print(Path.home())
print(Path.cwd().parent)
print(Path.cwd().parent.parent)
print(Path.cwd().parent.parent.parent)
for parent in Path.cwd().parents:
print(parent)
file_address=r'C:\Users\Administrator\Desktop\1.xlsx'
print(Path(file_address).name)
print(Path(file_address).suffix)
print(Path(file_address).suffixes)
print(Path(file_address).stem)
print(Path(file_address).with_name('22.xlsx'))
print(Path(file_address).with_suffix('.txt'))
print(Path(r'C:\Users',r'Administrator\Desktop',r'1.xlsx'))
print(Path(r'C:\Users',r'Administrator\Desktop').joinpath(r'1.xlsx'))
print(Path(r'C:\Users',r'Administrator\Desktop') / (r'1.xlsx'))
from pprint import pprint
file_path=Path(r'C:\Users\Administrator\Desktop')
pprint([*file_path.iterdir()],)
print(len([*file_path.iterdir()]))
example_path.mkdir(parents = True, exist_ok = True)
example_path.rmdir()file_path=Path(r'D:\a\b')
file_path.mkdir(parents = True, exist_ok = True)
file_path.rmdir()
file_path=Path(r'C:\Users\Administrator\Desktop\333.xlsx')
print(file_path.is_dir())
print(file_path.is_file())
print(file_path.is_absolute())
print(file_path.exists())
file_path=Path(r'C:\Users\Administrator\Desktop\1.xlsx')
print(file_path.stat())
print(file_path.stat().st_size)
import datetime
print(datetime.datetime.fromtimestamp(file_path.stat().st_ctime))