五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

python快速提取各個子文件夾下指定格式文件名字,并寫入txt文件中

2023-05-28 07:51 作者:仿真資料吧  | 我要投稿

編碼環(huán)境:python3.8

python3.8
import os

# 獲取當前路徑
current_path = "C:/Users/10474/Desktop/test"
# 定義輸出文件路徑
out_path = os.path.join(current_path, 'mp4name.txt')
# 創(chuàng)建輸出目錄
os.makedirs(os.path.dirname(out_path), exist_ok=True)

# 遍歷當前路徑下的所有文件夾
for subdir in os.listdir(current_path):
 ? ?subdir_path = os.path.join(current_path, subdir)
 ? ?print(subdir_path)
 ? ?
 ? ?# 判斷子文件夾是否存在
 ? ?if os.path.isdir(subdir_path):
 ? ? ? ?# 遍歷子文件夾下的文件
 ? ? ? ?for file in os.listdir(subdir_path):
 ? ? ? ? ? ?file_path = os.path.join(subdir_path, file)
 ? ? ? ? ? ?# 判斷文件是否以 .mp4 結(jié)尾,可以換成你的任意格式
 ? ? ? ? ? ?if os.path.isfile(file_path) and file.endswith('.mp4'):
 ? ? ? ? ? ? ? ?# 將文件名寫入輸出文件
 ? ? ? ? ? ? ? ?with open(out_path, 'a') as f:
 ? ? ? ? ? ? ? ? ? ?f.write(os.path.splitext(file)[0] + '\n')
 ? ? ? ? ? ? ? ? ? ?f.flush()
 ? ? ? ? ? ? ? ? ? ?f.close()

# 打印路徑信息
print(current_path)
print(out_path)

批處理命令:

@echo off

python get_mp4_name.py

pause

python3測試代碼文件:

鏈接:https://pan.baidu.com/s/1oGZJdLCV3RpQetaRDVODDA?

提取碼:9a89?



python快速提取各個子文件夾下指定格式文件名字,并寫入txt文件中的評論 (共 條)

分享到微博請遵守國家法律
额济纳旗| 油尖旺区| 临海市| 遂昌县| 赣州市| 桦川县| 松阳县| 嘉荫县| 札达县| 准格尔旗| 固安县| 贡山| 鹿泉市| 随州市| 岳阳市| 志丹县| 内黄县| 远安县| 揭东县| 瓦房店市| 苏尼特右旗| 西昌市| 新昌县| 昂仁县| 车险| 兴文县| 福州市| 甘南县| 宣化县| 乐东| 宁化县| 湛江市| 丽江市| 海城市| 克拉玛依市| 丰台区| 怀远县| 洛隆县| 灵寿县| 库尔勒市| 连平县|