MCPcopy Create free account
hub / github.com/ActiveState/code / rename

Function rename

recipes/Python/576443_Renamer/recipe-576443.py:148–166  ·  view source on GitHub ↗
(path,oldpath,first)

Source from the content-addressed store, hash-verified

146 return newname
147
148def rename(path,oldpath,first):
149 oldname = os.path.split(path)[1]
150 newname = getNewName(oldname,path,first)
151 newpath = os.path.join(os.path.split(path)[0],newname)
152 if first == 1:
153 undolog.write('%s Converted To %s\n' %(oldpath,newpath))
154 else:
155 undolog.write('%s Converted To %s\n' %(os.path.join(oldpath,oldname),newpath))
156 os.rename(path,newpath)
157 #print "Replacing %s with %s" %(path,newpath) For Debugging
158 if os.path.isdir(newpath):
159 #if the choice is Patternize, skip the subfolers
160 if choice == "Patternize" and first != 1:
161 pass
162 else:
163 if first != 1:
164 oldpath = os.path.join(oldpath,oldname)
165 for name in os.listdir(newpath):
166 rename(os.path.join(newpath,name),oldpath,0)
167
168def undo():
169 log = open('.Renamer.log','r')

Callers 1

recipe-576443.pyFile · 0.70

Calls 7

getNewNameFunction · 0.85
isdirMethod · 0.80
splitMethod · 0.45
joinMethod · 0.45
writeMethod · 0.45
renameMethod · 0.45
listdirMethod · 0.45

Tested by

no test coverage detected