Skip to content

Instantly share code, notes, and snippets.

@igorferreira
Created May 25, 2020 04:33
Show Gist options
  • Select an option

  • Save igorferreira/81306a29e2917840d5af2a592dd41b64 to your computer and use it in GitHub Desktop.

Select an option

Save igorferreira/81306a29e2917840d5af2a592dd41b64 to your computer and use it in GitHub Desktop.
Renomeia diretórios no formato data
import os
basedir = "/root/Scripts/myren/sandbox"
for old_name in os.listdir(basedir):
res = " ".join(reversed(old_name.rsplit('-')))
print("Reverse folder.: " + str(old_name))
new_name = str(res).replace(" ","-")
print("Reversing to...: " + str(new_name))
os.rename(os.path.join(basedir,old_name),os.path.join(basedir,new_name))
print("done!")
@igorferreira
Copy link
Author

igorferreira commented May 25, 2020

Diretório com as pastas assim:

tree sandbox/
sandbox/
├── 15-05-2020
└── 15-10-2011

Saída:

Reverse folder.: 15-10-2011
Reversing to...: 2011-10-15
done!
Reverse folder.: 15-05-2020
Reversing to...: 2020-05-15
done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment