Demo entry 6717693

script to rename files with search and replace


Submitted by anonymous on Feb 27, 2018 at 16:34
Language: Python. Code size: 627 Bytes.

def main(script,mySel,mySearch,myReplace) :
    print (mySel,mySearch,myReplace)
    mySel = open(mySel,"r")
    mySel =',')
    #print mySel
    for fileName in mySel:
        myDirname = os.path.dirname(fileName)
        myBaseName = os.path.basename(fileName)
        newBasename = myBaseName.replace(mySearch, myReplace)
        newFileName = os.path.join(myDirname,newBasename)
        print "{0} ===> {1}".format(myBaseName,newBasename)

if __name__ == '__main__':
            import os
            import sys

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).