python 将文件名写入 txt文件
发布日期:2021-06-24 15:21:07 浏览次数:4 分类:技术文章

本文共 1212 字,大约阅读时间需要 4 分钟。

# -*- coding: utf-8 -*-"""Created on Wed Jun 10 18:31:11 2020@author: xxxd"""import osimport syspath="G:\\BaiduNetdiskDownload\\最新月份(抖音热曲)";with open("musicName3.txt",'a',encoding='utf-8') as filetext:    for root,dirs,files in os.walk(path):        for name in files:            print(os.path.join(root,name));            filetext.write(os.path.join(root,name)+"\n");        for name in dirs:            print(os.path.join(root,name))            filetext.write(os.path.join(root,name)+"\n");    filetext.close();

在这里插入图片描述

# -*- coding: utf-8 -*-"""Created on Wed Jun 10 18:31:11 2020@author: xxxd"""import osimport sys#删除文件中的空格既可打印所有文件名path="G:\\BaiduNetdiskDownload";#path="G:\\BaiduNetdiskDownload\\不改音响提升10倍音质";#path="G:\\BaiduNetdiskDownload\\热歌";#path="G:\\BaiduNetdiskDownload\\周杰伦音乐";#path="G:\\BaiduNetdiskDownload\\最新月份(抖音热曲)";MusicNUM=0;with open("FileName20.txt",'a',encoding='utf-8') as filetext:    for root,dirs,files in os.walk(path):        for name in files:            print(os.path.join(root,name));            filetext.write(os.path.join(root,name)+"\n");        for name in dirs:            print(os.path.join(root,name))            filetext.write(os.path.join(root,name)+"\n");    filetext.close();

转载地址:https://blog.csdn.net/weixin_33595571/article/details/106672970 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:python 3 读取文件txt 打印print
下一篇:python 批量修改文件名称去除文件名中空格

发表评论

最新留言

留言是一种美德,欢迎回访!
[***.207.175.100]2024年03月30日 15时07分48秒