# 创建文件
fa = open('cs','a+') # 追加读写,创建
while True:
txt = ''
while len(txt)>1:
txt += input() + '\n'
with open('cs', 'a+') as f:
f.write(txt)
# Python扫描本地歌词文件并转txt
/storage/emulated/0/
# 创建文件
fa = open('cs','a+') # 追加读写,创建
while True:
txt = ''
while len(txt)>1:
txt += input() + '\n'
with open('cs', 'a+') as f:
f.write(txt)
# Python扫描本地歌词文件并转txt
/storage/emulated/0/
提取指定类型的文件
# -*- coding: utf-8 -*-
import os
def file_name(file_dir):
li=[]
for root, dirs, files in os.walk(file_dir):
for file in files:
if os.path.splitext(file)[1] == '.jpeg':
li.append(os.path.join(root, file))
return li
其中os.path.splitext()函数将路径拆分为文件名+扩展名,例如os.path.splitext(“D:/.jpg”)将得到”D:/aaa“+".jpg"。