python批量替換檔名中的共同字元

2021-08-09 00:00:32 字數 514 閱讀 6967

lesson 1-2 單詞解讀.mp4

1-2 單詞解讀.mp4

**如下

# -*- coding: utf-8 -*-

import os

#獲得資料夾下檔名列表

path=r"g:\baidunetdiskdownload\第1冊"

path=unicode(path,"utf8")

file_list=os.listdir(path)

#選擇要重新命名的資料夾路徑

os.chdir(path)

#將檔名中的lesson和空格用空字串替代

for file in file_list:

os.rename(file,file.replace("lesson ",""))

程式在除錯的時候感覺python的2.x版本中文編碼問題很擾人,最後將路徑編碼成utf-8格式解決。

python 批量替換檔名

你要是這樣學習看到這種噁心不,需求來了,批量替換檔名 movie name os.listdir h 妙味課堂 獲取所有的檔名列表 去掉node ts koa vue 程式設計開發 2018最新node ts koa vue 全棧開發 前後端 完結 0,1項還有最後一項跟這個無關 moview na...

Linux Shell 替換檔名中的空格

概述 使用 shell 替換 檔名中的空格 背景嘗試用 find 配合 xargs,在多個檔案裡找關鍵字 出現了問題 有空格的檔名,並不是很好處理 準備os centos7 場景需要在多個文字裡,查詢某個關鍵字 方法find 配合 xargs 問題檔名裡有空格 結果xargs 會把 帶有空格的檔名,...

批量替換資料夾名

bat檔案如下 echo off title 檔案bai名字元替du換 mode con cols 60 lines 20 檔案要是重名,會提示錯誤。setlocal enabledelayedexpansion color 0a 1set a set b set c cls echo.set p ...