欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Python 文件重命名工具代碼

 更新時(shí)間:2009年07月26日 09:46:19   作者:  
Python 文件重命名工具實(shí)現(xiàn)代碼。
復(fù)制代碼 代碼如下:

#Filename:brn.py
#Description: batch replace certain words in file names
#Use to bat rename the file in a dir(modify the suffix from a to b) for Windows Vista OS
import sys
import os
import fnmatch
import re
#parse params
p=input("Please input work directory(current path for enter):")
if p=='\r':
p='.'
p=p.rstrip('\r')
print (p)
while not os.path.exists(p):
print (p+' is not existed.Please input the work directory:')
p=input("Please input work directory(current path for enter):")
s=input("Please enter the words which need be modified(must):")
while s=='\r':
s=input("Please enter the words which need be replaced(must):")
s=s.rstrip('\r')
d=input("Please enter the words which want to change to(must):")
while d=='\r':
d=input("Please enter the words which want to change to(must):")
d=d.rstrip('\r')
try:
sure=input("Are you sure to rename the file named *"+s+"*"+" to *"+d+"*"+" in directory "+p+"? y/n:")
sure=sure.rstrip('\r')
if sure!='y':
print ("Cancel")
else:
for root, dirs, files in os.walk(p, True):
for file in files:
print (os.path.join(root,file))
if os.path.isfile(os.path.join(root,file)):#Only file is file,not a dir ,do this
if fnmatch.fnmatch(file, '*'+s+'*'):
f=str(file).replace(s,d)
if p=='.':
command='move '+str(file)+" "+f
else:
command="move "+os.path.join(root,file)+" "+os.path.join(root,f)
print (command)
if os.system(command)==0:#do actual rename
print ("Rename "+str(file)+" to "+f+" success")
else:
print ("Rename "+str(file)+" to "+f+" failed")
#else:
#print str(file)+" is a directory.omit"
except IndexError:
print (IndexError.message)

相關(guān)文章

  • Python 通過URL打開圖片實(shí)例詳解

    Python 通過URL打開圖片實(shí)例詳解

    這篇文章主要介紹了Python 通過URL打開圖片實(shí)例詳解的相關(guān)資料,需要的朋友可以參考下
    2017-06-06
  • python如何使用opencv提取光流詳解

    python如何使用opencv提取光流詳解

    這篇文章主要給大家介紹了關(guān)于python如何使用opencv提取光流的相關(guān)資料,文中通過圖文以及實(shí)例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2022-09-09
  • Python?FastAPI?Sanic?Tornado?與Golang?Gin性能實(shí)戰(zhàn)對(duì)比

    Python?FastAPI?Sanic?Tornado?與Golang?Gin性能實(shí)戰(zhàn)對(duì)比

    本文將深入比較Python的FastAPI、Sanic、Tornado以及Golang的Gin框架的各種特性、性能表現(xiàn)以及適用場(chǎng)景,通過詳實(shí)的性能測(cè)試和實(shí)際示例代碼,將探討它們?cè)跇?gòu)建現(xiàn)代高性能應(yīng)用中的優(yōu)劣勢(shì),以便開發(fā)者根據(jù)需求做出明智的選擇
    2024-01-01
  • POC漏洞批量驗(yàn)證程序Python腳本編寫

    POC漏洞批量驗(yàn)證程序Python腳本編寫

    這篇文章主要為大家介紹了POC漏洞批量驗(yàn)證程序Python腳本編寫的完整示例代碼,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步
    2022-02-02
  • python 常見字符串與函數(shù)的用法詳解

    python 常見字符串與函數(shù)的用法詳解

    這篇文章主要介紹了python 常見字符串與函數(shù)的用法,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2018-11-11
  • Python Pygame制作雪夜煙花景

    Python Pygame制作雪夜煙花景

    這篇文章主要為大家詳細(xì)介紹了如何利用Python中的Pygame模塊制作一個(gè)雪夜煙花景,文中的示例代碼講解詳細(xì),對(duì)我們學(xué)習(xí)Python有一定幫助,需要的可以參考一下
    2022-01-01
  • Python使用sklearn庫實(shí)現(xiàn)的各種分類算法簡單應(yīng)用小結(jié)

    Python使用sklearn庫實(shí)現(xiàn)的各種分類算法簡單應(yīng)用小結(jié)

    這篇文章主要介紹了Python使用sklearn庫實(shí)現(xiàn)的各種分類算法,結(jié)合實(shí)例形式分析了Python使用sklearn庫實(shí)現(xiàn)的KNN、SVM、LR、決策樹、隨機(jī)森林等算法實(shí)現(xiàn)技巧,需要的朋友可以參考下
    2019-07-07
  • Python 第三方日志框架loguru使用

    Python 第三方日志框架loguru使用

    使用Python自帶的logging模塊記錄日志,但是總覺得不夠優(yōu)雅。 Loguru解決了這個(gè)問題,接下來通過本文給大家介紹Python 第三方日志框架loguru使用,感興趣的朋友跟隨小編一起看看吧
    2021-05-05
  • Python實(shí)現(xiàn)匯率轉(zhuǎn)換操作

    Python實(shí)現(xiàn)匯率轉(zhuǎn)換操作

    這篇文章主要介紹了Python實(shí)現(xiàn)匯率轉(zhuǎn)換操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2020-05-05
  • Python獲取某一天是星期幾的方法示例

    Python獲取某一天是星期幾的方法示例

    這篇文章主要介紹了Python獲取某一天是星期幾的方法,結(jié)合完整實(shí)例形式分析了Python針對(duì)日期與時(shí)間的相關(guān)計(jì)算技巧,需要的朋友可以參考下
    2017-01-01

最新評(píng)論