Created
January 2, 2023 16:34
-
-
Save srezasm/0e5e0692cab8f641313553f3d8d8f16f to your computer and use it in GitHub Desktop.
Revisions
-
srezasm created this gist
Jan 2, 2023 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,29 @@ from os import listdir, rename from os.path import isfile, isdir, join def scroll_dir(dpath): children = [c for c in listdir(dpath)] for c in children: p = join(dpath, c) if isdir(p): scroll_dir(p) elif isfile(p): change_file_name(p) def change_file_name(fpath): newname = str(fpath)\ .replace(startpath, "")\ .lstrip("/")\ .replace("/", "__") newname = join(startpath, newname) rename(fpath, newname) print(f'{fpath} -> {newname}') if __name__ == "__main__": print("/base/dir/subdir/file.mp4 -> /base/dir__subdir__file.mp4") startpath = input("base dir path: ") scroll_dir(startpath)