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

Function main

recipes/Python/577342_AutoRenamepy/recipe-577342.py:4–22  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2import sys
3
4def main():
5 program = os.path.abspath(sys.argv[0])
6 # Get the current working directory and
7 # walk through it and its subdirectories.
8 cwd = os.getcwd()
9 for root, dirs, files in os.walk(cwd, False):
10 # Rename all of the folders.
11 for index, name in enumerate(dirs):
12 old_name = os.path.join(root, name)
13 new_name = os.path.join(root, str(index))
14 rename(old_name, new_name)
15 # Rename all of the files.
16 for index, name in enumerate(files):
17 old_name = os.path.join(root, name)
18 if old_name != program:
19 name, ext = os.path.splitext(name)
20 name_ext = '{}{}'.format(index, ext)
21 new_name = os.path.join(root, name_ext)
22 rename(old_name, new_name)
23
24def rename(old, new):
25 try:

Callers 1

recipe-577342.pyFile · 0.70

Calls 7

strFunction · 0.85
getcwdMethod · 0.80
renameFunction · 0.70
enumerateFunction · 0.50
walkMethod · 0.45
joinMethod · 0.45
formatMethod · 0.45

Tested by

no test coverage detected