#_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. WAMP中的mysql设置密码(默认密码为空)及phpmyadmin的配置

    来自:  http://wenku.baidu.com/link?url=J4K28e1kt-_ykJLsOtS1b5T6hKj5IzL5hXSKIiB133AvPCUXLlxGKScsBsxi0mA ...

  2. 2019-9-2-win10-uwp-布局

    title author date CreateTime categories win10 uwp 布局 lindexi 2019-09-02 12:57:38 +0800 2018-2-13 17: ...

  3. 8.Struts2拦截器

    1. 拦截器的概述 * 拦截器就是AOP(Aspect-Oriented Programming)的一种实现.(AOP是指用于在某个方法或字段被访问之前,进行拦截然后在之前或之后加入某些操作.) * ...

  4. Ruby 环境变量

    Ruby 环境变量 Ruby 解释器使用下列环境变量来控制它的行为.ENV 对象包含了所有当前设置的环境变量列表. 变量 描述 DLN_LIBRARY_PATH 动态加载模块搜索的路径. HOME 当 ...

  5. Perl 循环

    Perl 循环 有的时候,我们可能需要多次执行同一块代码.一般情况下,语句是按顺序执行的:函数中的第一个语句先执行,接着是第二个语句,依此类推. 编程语言提供了更为复杂执行路径的多种控制结构. 循环语 ...

  6. 利用html2canvas截图,得到base64上传ajax

    <script type="text/javascript" src="js/html2canvas.js"></script> //布 ...

  7. JAVA大数——lightoj1024

    要用 System.gc() 清理内存 类必须命名成Main,一些大整数的操作 import java.math.BigInteger; import java.util.Scanner; publi ...

  8. 移动Windows开始按钮到任务栏中的任何位置

    uses CommCtrl; procedure TForm1.Button1Click(Sender: TObject); var vHandle: THandle; vCount: Integer ...

  9. P1624 单词缩写

    P1624 单词缩写 题目描述 树树发现好多计算机中的单词都是缩写,如GDB是全称Gnu DeBug的缩写.但是,有时候缩写对应的全称会不固定,如缩写LINUX可以理解为: (1) LINus’s U ...

  10. curl命令,curl实现post,curl监控网页shell脚本,curl多进程实现并控制进程数,

    cURL > Docs > Tutorial:  http://curl.haxx.se/docs/httpscripting.html 下载单个文件,默认将输出打印到标准输出中(STDO ...