contrib: add bulkrename.py
This commit is contained in:
parent
a61435e8fc
commit
852b445f90
1 changed files with 37 additions and 0 deletions
37
contrib/bulkrename.py
Executable file
37
contrib/bulkrename.py
Executable file
|
@ -0,0 +1,37 @@
|
|||
#!/bin/env python
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
tmpname = ".bulkrename-tmp"
|
||||
|
||||
files = os.listdir(".")
|
||||
tmpfile = open(tmpname, "w")
|
||||
tmpfile.write("[ ] <-- mark with x to confirm\n")
|
||||
for f in files:
|
||||
tmpfile.write(f + "\n")
|
||||
tmpfile.close()
|
||||
|
||||
editor = os.environ.get("EDITOR")
|
||||
subprocess.call([editor, tmpname])
|
||||
|
||||
tmpfile = open(tmpname, "r")
|
||||
input = tmpfile.readlines()
|
||||
tmpfile.close()
|
||||
|
||||
if len(input) != len(files) + 1:
|
||||
os.remove(tmpname)
|
||||
exit(1)
|
||||
if input[0][1] != 'x':
|
||||
os.remove(tmpname)
|
||||
exit(1)
|
||||
|
||||
print("starting bulk rename")
|
||||
for i in range(len(files)):
|
||||
original = files[i]
|
||||
new = input[i + 1].rstrip()
|
||||
if (original != new):
|
||||
print("rename: \"" + original + "\" -> \"" + new + "\"")
|
||||
os.rename(original, new)
|
||||
print("done")
|
||||
|
||||
os.remove(tmpname)
|
Loading…
Reference in a new issue