Created
January 2, 2023 16:34
-
-
Save srezasm/0e5e0692cab8f641313553f3d8d8f16f to your computer and use it in GitHub Desktop.
move files into base directory python script
This file contains 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 characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment