文件的操作repeat
#_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的更多相关文章
- python文件的操作
文件的操作,归根结底就只有两种:打开文件.操作文件 一.打开文件:文件句柄 = open('文件路径', '模式') python中打开文件有两种方式,即:open(...) 和 file(...) ...
- Linux命令-文件文本操作grep
文件文本操作 grep 在文件中查找符合正则表达式条件的文本行 cut 截取文件中的特定字段 paste 附加字段 tr 字符转换或压缩 sort 调整文本行的顺序,使其符合特定准则 uniq 找出重 ...
- [No000083]文件与文件夹操作
#region Folder option 文件夹操作 /// <summary> /// 指定目录是否存在 /// </summary> /// <param name ...
- PHP 文件夹操作「复制、删除、查看大小」递归实现
PHP虽然提供了 filesize.copy.unlink 等文件操作的函数,但是没有提供 dirsize.copydir.rmdirs 等文件夹操作的函数(rmdir也只能删除空目录).所以只能手动 ...
- c语言文件读写操作总结
C语言文件读写操作总结 C语言文件操作 一.标准文件的读写 1.文件的打开 fopen() 文件的打开操作表示将给用户指定的文件在内存分配一个FILE结构区,并将该结构的指针返回给用户程序,以后用户程 ...
- OC NSFileHandle(文件内容操作)
OC NSFileHandle(文件内容操作) 初始化 [NSFileHandle fileHandleForUpdatingAtPath:@"data.txt"]; //file ...
- python对文件的操作
一.python中对文件.文件夹操作时经常用到的os模块和shutil模块常用方法. 1.得到当前工作目录,即当前Python脚本工作的目录路径: os.getcwd() 2.返回指定目录下的所有文件 ...
- [转]Android - 文件读写操作 总结
转自:http://blog.csdn.net/ztp800201/article/details/7322110 Android - 文件读写操作 总结 分类: Android2012-03-05 ...
- Adobe AIR对本地文件(XML文件)的操作
引用:http://addiwang.blog.163.com/blog/static/118130772011221114230288/ Air的文件操做主要涉及两个类,FIle和FileStrea ...
随机推荐
- plsql创建一个表、序列、和触发器
plsql创建表后不能直接让id递增,因此要手动创建,下面是例子: 1.创建表 SQL: create table student(id number primary key,name varchar ...
- 22-4-isarry
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- C#获取本月开始日期和结束日期
DateTime dt = DateTime.Now; //本月第一天时间 DateTime dt_First = dt.AddDays( - (dt.Day)); //获得某年某月的天数 int y ...
- 最基础知识 sql之left join、right join、inner join的区别
sql之left join.right join.inner join的区别 left join(左联接) 返回包括左表中的所有记录和右表中联结字段相等的记录 right join(右联接) 返回包括 ...
- 笔记48 Spring+SpringMVC+Hibernate整合
搭建Spring+SpringMVC+Hibernate的框架的思路如下: 1.创建Maven项目,按需映入Maven包依赖. 2.搭建Spring:配置Spring对控件层Bean的注入. 3.搭建 ...
- 常用的Docker镜像及处理命令
常用的镜像命令 docker run -d --name dockerui -p : -v /var/run/docker.sock:/var/run/docker.sock abh1nav/dock ...
- vue App项目 首页
1. 下载 npm i mint-ui -S 2. 引入 import MintUI from 'mint-ui' import 'mint-ui/lib/style.css' Vue.use(Min ...
- nodejs MYSQL数据库执行多表查询
1.设计数据库 2.设计数据库表 genres表: books表: 3.安装MySQL模块 4. 代码编写 (1) 第一种方法: 在query中使用nextTables属性,将属性值设置为ture d ...
- 判断有向无环图(DAG)
1.拓扑排序 bfs 所有入度为0的先入选. 2.tarjan 1个点1个集合 3.暴力 一个点不能重新到达自己
- flume配置参数的意义
1.监控端口数据: flume启动: [bingo@hadoop102 flume]$ bin/flume-ng agent --conf conf/ --name a1 --conf-file jo ...