Skip to content

Instantly share code, notes, and snippets.

@ReddyyZ
Created August 7, 2020 22:10
Show Gist options
  • Save ReddyyZ/8bad67354576ec3ccbb5707ee68cbf62 to your computer and use it in GitHub Desktop.
Save ReddyyZ/8bad67354576ec3ccbb5707ee68cbf62 to your computer and use it in GitHub Desktop.
Script para renomear vários arquivos automaticamente.
# -*- coding: utf-8 -*-
import pathlib,argparse
def arguments():
parser = argparse.ArgumentParser()
parser.add_argument('-d','--dir',help="Dir of files",default='.',metavar='')
parser.add_argument('-b','--banned',help="Banned words to remove",nargs='+',required=True,metavar='')
args = parser.parse_args()
return (args.dir,args.banned)
if __name__ == "__main__":
_dir, banned_words = arguments()
banned_words = "".join(x + '' if banned_words[-1] == x else x for x in banned_words)
p = pathlib.Path(_dir)
files = list(p.glob('*'))
i = 0
for file in files:
f_name = file.name
if banned_words in file.name:
file.rename(f_name.replace(banned_words,""))
i += 1
print(f"{i} files renamed!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment