-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/usr/bin/env python | ||
# -*-*- encoding: utf-8 -*-*- | ||
# Created: Wed, 18 Jun 2014 21:52:03 +0200 | ||
|
||
""" | ||
Script para renomear arquivos recursivamente, trocando espaços por underscores | ||
e caracteres unicode por equivalentes em ascii. | ||
""" | ||
__author__ = "Julio Batista Silva" | ||
__copyright__ = "" | ||
__license__ = "GPL v3" | ||
__version__ = "1.0" | ||
|
||
import argparse | ||
import sys | ||
import os | ||
import itertools | ||
from unidecode import unidecode | ||
|
||
|
||
def main(rs): | ||
for root, dirs, files in os.walk('./', topdown=False): | ||
for path in itertools.chain(files, dirs): | ||
old = os.path.join(root, path) | ||
if rs: | ||
new = os.path.join(root, unidecode(path.replace(' ', '_'))) | ||
else: | ||
new = os.path.join(root, unidecode(path)) | ||
if not os.path.exists(new): | ||
os.rename(old, new) | ||
return 0 | ||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser( | ||
description='Renomeia arquivos recursivamente') | ||
parser.add_argument('-rs', '--remove_space', dest="rs", | ||
action='store_true', | ||
help='Troca espaço por underscore.') | ||
args = parser.parse_args() | ||
|
||
sys.exit(main(args.rs)) |