#_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

文件的操作repeat的更多相关文章

  1. python文件的操作

    文件的操作,归根结底就只有两种:打开文件.操作文件 一.打开文件:文件句柄 = open('文件路径', '模式') python中打开文件有两种方式,即:open(...) 和  file(...) ...

  2. Linux命令-文件文本操作grep

    文件文本操作 grep 在文件中查找符合正则表达式条件的文本行 cut 截取文件中的特定字段 paste 附加字段 tr 字符转换或压缩 sort 调整文本行的顺序,使其符合特定准则 uniq 找出重 ...

  3. [No000083]文件与文件夹操作

    #region Folder option 文件夹操作 /// <summary> /// 指定目录是否存在 /// </summary> /// <param name ...

  4. PHP 文件夹操作「复制、删除、查看大小」递归实现

    PHP虽然提供了 filesize.copy.unlink 等文件操作的函数,但是没有提供 dirsize.copydir.rmdirs 等文件夹操作的函数(rmdir也只能删除空目录).所以只能手动 ...

  5. c语言文件读写操作总结

    C语言文件读写操作总结 C语言文件操作 一.标准文件的读写 1.文件的打开 fopen() 文件的打开操作表示将给用户指定的文件在内存分配一个FILE结构区,并将该结构的指针返回给用户程序,以后用户程 ...

  6. OC NSFileHandle(文件内容操作)

    OC NSFileHandle(文件内容操作) 初始化 [NSFileHandle fileHandleForUpdatingAtPath:@"data.txt"]; //file ...

  7. python对文件的操作

    一.python中对文件.文件夹操作时经常用到的os模块和shutil模块常用方法. 1.得到当前工作目录,即当前Python脚本工作的目录路径: os.getcwd() 2.返回指定目录下的所有文件 ...

  8. [转]Android - 文件读写操作 总结

     转自:http://blog.csdn.net/ztp800201/article/details/7322110 Android - 文件读写操作 总结 分类: Android2012-03-05 ...

  9. Adobe AIR对本地文件(XML文件)的操作

    引用:http://addiwang.blog.163.com/blog/static/118130772011221114230288/ Air的文件操做主要涉及两个类,FIle和FileStrea ...

随机推荐

  1. iOS组件化开发-CocoaPods安装

    首先要检查Mac是否安装了rvm(ruby version manager).打开终端,输入指令$ rvm -v ,若没有安装 curl -L https://get.rvm.io | bash -s ...

  2. python pathlib模块详解

    python pathlib模块详解    

  3. Centos Apache 80 代理Tomcat 8080端口

    运行环境:Centos 6.5 Apache: 2.2.5 开启apache proxy的相应模块 编辑 /etc/httpd/conf/httpd.conf文件 sudo vim /etc/http ...

  4. struts2-convention-plugin零配置

    零配置的意思并不是说没有配置,而是通过约定大于配置的方式,大量通过约定来调度页面的跳转而使得配置大大减少. <?xml version="1.0" encoding=&quo ...

  5. ThinkPHP框架数组定义

    PHP数组定义 ThinkPHP框架中所有配置文件的定义格式均采用返回PHP数组的方式,格式为: //项目配置文件 return array( 'DEFAULT_MODULE' => 'Inde ...

  6. 牛客多校第三次B——线段树维护线性基交

    写线性基交函数时调试了半天.. #include<bits/stdc++.h> using namespace std; #define ll long long #define maxn ...

  7. NX二次开发-UFUN添加工程图投影视图UF_DRAW_add_orthographic_view

    NX9+VS2012 #include <uf.h> #include <uf_draw.h> #include <uf_obj.h> #include <u ...

  8. opencv-霍夫直线变换与圆变换

    转自:https://blog.csdn.net/poem_qianmo/article/details/26977557 一.引言 在图像处理和计算机视觉领域中,如何从当前的图像中提取所需要的特征信 ...

  9. docker实用参数

    docker images:查看docker镜像docker ls:查看运行中的docker 镜像docker run -d -p 80:80 -v /home/xxxxx/nginx-conf/ht ...

  10. 由于某些原因无法博客搬家,现在换马甲了 http://blog.csdn.net/qq_32066409

    由于位置原因无法博客搬家,现在换马甲到csdn了地址如下http://blog.csdn.net/qq_32066409