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: pandas.Series如何只保留str,去除重複值?#isinstance(x:Any, str) -> bool #.drop_duplicates() #Series.apply( function )逐元素應用function運算 #DataFrame.apply( function )逐Series應用function運算 .drop_duplicates() 跟.unique()有何差別? df.drop_duplicates() 等效於 df[~df.duplicated()] Python: pandas.Series如何只保留str,去除重複值?#isinstance(x:Any, str) -> bool #.drop_duplicates() #Series.apply( function )逐元素應用function運算 #DataFrame.apply( function )逐Series應用function運算 .drop_duplicates() 跟.unique()有何差別? df.drop_duplicates() 等效於 df[~df.duplicated()]](https://i0.wp.com/savingking.com.tw/wp-content/uploads/2024/11/20241123194900_0_5218de.png?quality=90&zoom=2&ssl=1&resize=350%2C233)









近期留言