操作文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
| import os import shutil from datetime import datetime
dir = '/data' file = '/data/1.txt'
os.mkdir(dir)
os.makedirs(dir + '/123')
shutil.copyfile('old', 'new')
shutil.copytree('olddir', 'newdir')
os.rename('odl', 'new')
shutil.move('old', 'new')
os.rmdir(dir)
os.removedirs(dir)
os.listdir(dir)
os.remove(file)
if os.path.exists(dir): pass
if os.path.isfile(file): pass
if os.path.isdir(dir): pass
if os.path.isabs(dir): pass
os.stat(file)
os.stat(file).st_size os.path.getsize(file)
os.path.basename(filePath)
os.path.dirname(filePath)
os.path.abspath(file)
fromtimestamp = datetime.fromtimestamp(int(os.path.getctime(filePath))).date() print(str(fromtimestamp))
basename = os.path.basename(path) extension = os.path.splitext(basename)[1]
sorted(os.listdir(path))
|
本文地址: https://github.com/maxzhao-it/blog/post/cd61337e/