#_author:来童星
#date:2019/12/15
import os
#1
# print(os.name)# nt------>windows操作系统
#2 用于获取当前操作系统的换行符
# print(os.linesep)# 为什么不显示
# # 用于获取当前操作系统所使用的路径分隔符
# print(os.sep)# \
#4.返回当前工作目录
# print(os.getcwd())# D:\pycharm_file\new_files\learn_python\week8\day_7
# 5. 返回指定路径下的文件和目录信息
# print(os.listdir('week7\\day1\\day2')) !!!!有问题
# 6.
# os.mkdir('d:\\ltx1')
#7.判断目录是否存在
# os.makedirs('d:\\demo\\test')
# path='d:\\demo'
# if not os.path.exists(path):
# os.makedirs(path)
# print('目录创建成功')
# else:
# print('目录创建失败')
# 8 拼接路径
# print(os.path.abspath('dir_operator_2.py'))# D:\pycharm_file\new_files\learn_python\week8\day_7\dir_operator_2.py
# print(os.path.join('D:\pycharm_file\\new_files\learn_python','week8\\day_7\\dir_operator_2.py'))
# D:\pycharm_file\new_files\learn_python\week8\day_7\dir_operator_2.py
# 9.删除目录
# import shutil# 删除不为空的母鹿
# path='e:\\demo'
# if os.path.exists(path):
# shutil.rmtree(path)
# print('删除成功')
# else:
# print('删除失败')
#
# os.makedirs('E:\\demo\\test\\a.txt')
# path='E:\\demo'
# if os.path.exists(path):
# os.rmdir(path)
# print('删除成功')
# else:
# print('删除失败')
#10遍历文件
# tuples='D:\\pycharm_file\\new_files\\learn_python\\week7\\day1'
# for item in os.walk(tuples,False):
# print(item)
#从上往下遍历
# print(os.walk(tuples))# <generator object walk at 0x00000289EA60D830>
# ('D:\\pycharm_file\\new_files\\learn_python\\week7\\day1', ['day2', 'day5', 'DAY7'], ['t1.py', 't2.py', 't3.py', 't4.py', 't5.py', 't6.py', 'test1.py', 'test_1.py', 'test_2.py', 'test_3.py'])
# ('D:\\pycharm_file\\new_files\\learn_python\\week7\\day1\\day2', [], ['t1.py', 't2.py', 'test2.py', 'test3.py'])
# ('D:\\pycharm_file\\new_files\\learn_python\\week7\\day1\\day5', [], ['backtime_fun.py', 'chengyutk.py', 'kj_dattetime_.py', 'kj_print.py', 't1.py', 't2.py', 't3.py', 't4.py', 't5.py', 'wechat_fun.py'])
# ('D:\\pycharm_file\\new_files\\learn_python\\week7\\day1\\DAY7', [], [])
# 从下往上遍历(遍历最后一级别子目录)
# ('D:\\pycharm_file\\new_files\\learn_python\\week7\\day1\\day2', [], ['t1.py', 't2.py', 'test2.py', 'test3.py'])
# ('D:\\pycharm_file\\new_files\\learn_python\\week7\\day1\\day5', [], ['backtime_fun.py', 'chengyutk.py', 'kj_dattetime_.py', 'kj_print.py', 't1.py', 't2.py', 't3.py', 't4.py', 't5.py', 'wechat_fun.py'])
# ('D:\\pycharm_file\\new_files\\learn_python\\week7\\day1\\DAY7', [], [])
# ('D:\\pycharm_file\\new_files\\learn_python\\week7\\day1', ['day2', 'day5', 'DAY7'], ['t1.py', 't2.py', 't3.py', 't4.py', 't5.py', 't6.py', 'test1.py', 'test_1.py', 'test_2.py', 'test_3.py'])
# 11---》高级文件操作 # from urllib.request import urlopen
# import gevent
# def f(url):
# print('get:%s'%url)
# resp=urlopen(url)
# date=resp.read()
# with open('message123.html', 'wb') as file:
# file.write(date)
# print('%d bytes Received From %s'%(len(date),url))
# f('http://www.taobao.com/') # if os.path.exists('message123.html'):
# os.remove('message123.html')
# print('success')
# else:
# print('file')
# 12 重命名文件
# src='m123.txt'
# dst='message123.txt'
# if os.path.exists(src):
# print('文件存在')
# os.rename(src,dst)
# else:
# print('文件不存在')
#
# src='D:\\pycharm_file\\new_files\\learn_python\\week8\\day2'
# dst='D:\\pycharm_file\\new_files\\learn_python\\week8\\day_2'
# if os.path.exists(src):
# print('dir更新完毕')
# os.rename(src,dst)
# else:
# print('dir不存在')
#13.
if os.path.exists('message123.txt'):
fileinfo=os.stat('message123.txt')
print('文件完整路径',os.path.abspath('message123.txt'))# 文件完整路径 D:\pycharm_file\new_files\learn_python\week8\day_7\message123.txt
print('文件大小',fileinfo.st_size)#文件大小 43
print('最后一次修改时间',fileinfo.st_mtime)#最后一次修改时间 1576416534.7083335

最新文章

  1. KnockoutJS 3.X API 第四章 表单绑定(6) click绑定
  2. 创建html元素
  3. C++产生随机数四则运算
  4. WOSA协议(转)
  5. new tips
  6. hdu 2476(第一道区间dp)
  7. mysql中 group_concat长度限制
  8. Linux下搭建jdk
  9. apache开源项目--HBase
  10. 技术QQ群
  11. hdu4770:Lights Against Dudely(回溯 + 修剪)
  12. js中的深拷贝与浅拷贝
  13. spark、standalone集群 (2)集群zookeeper 热备
  14. python 08
  15. 安装cmake
  16. 第一行代码 -3-2 软件也要拼脸蛋-UI界面-更强大的滚动条-RecyclerView
  17. 依赖反转Ioc和unity,autofac,castle框架教程及比较
  18. Vim-编辑器之神
  19. WPF 中textBox实现只输入数字
  20. OpenCV实战:人脸关键点检测(FaceMark)

热门文章

  1. canvas 画一条折线
  2. 使用dd生成文件
  3. jq-demo-楼梯效果
  4. QT install
  5. Intergalactic Map SPOJ - IM
  6. NX二次开发-UFUN特征选择对话框UF_UI_select_feature
  7. NX二次开发-UFUN选择草图对话框UF_UI_select_sketch
  8. HDU3605: Escape-二进制优化建图-最大流
  9. git 安装 使用过程遇到的问题
  10. Python-爬虫之股转系统下载文件自动翻页