python小程序,批量文件的转换

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/VABTC/article/details/80378100
实现多个字符串的批量转换
import re
import os
s = os.sep

root = "G:\daizhuan"

for i in os.listdir(root):

    if os.path.isfile(os.path.join(root,i)):
        print ("i")
        filePath = os.path.join(root,i)
        a= open(filePath,'r') #打开所有文件
        str = a.read()

        str = str.replace("<div", "<view") # 将字符串里前面全部替换为后面
        str = str.replace("<p","<view")
        str = str.replace("div>", "view>")
        str = str.replace("p>", "view>")

        print (os.path.join(root,i))
        print (str)
        b = open(filePath,'w')
    b.write(str) #再写入
    b.close() #关闭文件



猜你喜欢

转载自blog.csdn.net/VABTC/article/details/80378100