| 2 | import sys |
| 3 | |
| 4 | def 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 | |
| 24 | def rename(old, new): |
| 25 | try: |