d:\Temp 資料夾
底下的檔案如下:
code:
# -*- coding: utf-8 -*-
"""
Created on Wed Oct 4 18:26:15 2023
@author: SavingKing
"""
import glob
import os
dirname = r"D:\Temp" #使用者自行修改
basename ="*.txt" #使用者自行修改
fpath = os.path.join(dirname , basename)
#'D:\\Temp\\*.txt'
original_str = "ex_pn" #使用者自行修改
new_str = "VIZ_1395A" #使用者自行修改
lis_fpath = glob.glob(fpath)
# ['D:\\Temp\\ex_pn_SPEC1.txt', 'D:\\Temp\\ex_pn_SPEC2.txt']
# lis_new_path = []
for path in lis_fpath:
new_path = path.replace(original_str , new_str)
# lis_new_path.append(new_path)
os.rename(path , new_path)程式執行後:

順便示範以下幾個函式:

推薦hahow線上學習python: https://igrape.net/30afN



![Python爬蟲:BeautifulSoup的 .find_all() 與 .find() 與 .select(‘標籤名[屬性名1=”屬性值1″][屬性名2=”屬性值2″]’) ; from bs4 import BeautifulSoup ; Live Server(可以預覽HTML的VS Code套件) Python爬蟲:BeautifulSoup的 .find_all() 與 .find() 與 .select(‘標籤名[屬性名1=”屬性值1″][屬性名2=”屬性值2″]’) ; from bs4 import BeautifulSoup ; Live Server(可以預覽HTML的VS Code套件)](https://i1.wp.com/savingking.com.tw/wp-content/uploads/2025/03/20250330190318_0_925655.jpg?quality=90&zoom=2&ssl=1&resize=350%2C233)



![Python TQC考題910 學生基本資料, print(line.decode(“utf-8”)), if line.decode(“utf-8″).split()[2] ==”0”: female += 1 Python TQC考題910 學生基本資料, print(line.decode(“utf-8”)), if line.decode(“utf-8″).split()[2] ==”0”: female += 1](https://i0.wp.com/savingking.com.tw/wp-content/uploads/2022/05/20220514163621_72.png?quality=90&zoom=2&ssl=1&resize=350%2C233)


近期留言