Spaces:
Running
Running
| #!/usr/bin/env python3 | |
| import os | |
| # cd checkpoints | |
| # Root folder where your symlinks are located | |
| folder = "." | |
| old_prefix = "/Users/cuongpc/" | |
| new_prefix = "/home/user/" | |
| old_prefix_1 = "../../../../../root/" | |
| for entry in os.listdir(folder): | |
| path = os.path.join(folder, entry) | |
| if os.path.islink(path): | |
| target = os.readlink(path) | |
| if target.startswith(old_prefix) or target.startswith(old_prefix_1): | |
| new_target = target.replace(old_prefix, new_prefix, 1).replace(old_prefix_1, new_prefix, 1) | |
| print(f"Updating: {path}\n {target} -> {new_target}") | |
| os.remove(path) # remove old symlink | |
| os.symlink(new_target, path) | |