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://i0.wp.com/savingking.com.tw/wp-content/uploads/2025/03/20250330190318_0_925655.jpg?quality=90&zoom=2&ssl=1&resize=350%2C233)
![Python: pandas.DataFrame (df) 的取值: df [單一字串] 或df [list_of_strings] 選取一個或多個columns; df [切片] 或 df [bool_Series] 選取多個rows #bool_Series長度同rows, index也需要同df.index ,可以使用.equals() 確認: df.index.equals(mask.index) Python: pandas.DataFrame (df) 的取值: df [單一字串] 或df [list_of_strings] 選取一個或多個columns; df [切片] 或 df [bool_Series] 選取多個rows #bool_Series長度同rows, index也需要同df.index ,可以使用.equals() 確認: df.index.equals(mask.index)](https://i0.wp.com/savingking.com.tw/wp-content/uploads/2025/04/20250420212553_0_6fb2c3.png?quality=90&zoom=2&ssl=1&resize=350%2C233)
![Python 表達式中的魔法:用海象運算子讓斷詞程式碼更乾淨 [w_clean for w in words if (w_clean:=w.lower().strip()) and w_clean not in STOPWORDS] Python 表達式中的魔法:用海象運算子讓斷詞程式碼更乾淨 [w_clean for w in words if (w_clean:=w.lower().strip()) and w_clean not in STOPWORDS]](https://i1.wp.com/savingking.com.tw/wp-content/uploads/2026/02/20260210083748_0_a7d9bf.png?quality=90&zoom=2&ssl=1&resize=350%2C233)

近期留言