Use argparse for inputrename.
This commit is contained in:
parent
ae6954d573
commit
0c481f454f
1 changed files with 30 additions and 8 deletions
|
@ -3,12 +3,34 @@ import sys
|
||||||
|
|
||||||
from voussoirkit import winglob
|
from voussoirkit import winglob
|
||||||
|
|
||||||
keyword = sys.argv[1]
|
import argparse
|
||||||
pattern = f'*{keyword}*'
|
import sys
|
||||||
|
|
||||||
|
def inputrename_argparse(args):
|
||||||
|
pattern = f'*{args.keyword}*'
|
||||||
|
|
||||||
files = winglob.glob(pattern)
|
files = winglob.glob(pattern)
|
||||||
|
prev = None
|
||||||
for file in files:
|
for file in files:
|
||||||
print(file)
|
print(file)
|
||||||
this = input('> ')
|
this = input('> ')
|
||||||
|
if this == '' and prev is not None:
|
||||||
|
this = prev
|
||||||
if this:
|
if this:
|
||||||
os.rename(file, file.replace(keyword, this))
|
os.rename(file, file.replace(args.keyword, this))
|
||||||
|
prev = this
|
||||||
|
|
||||||
|
def main(argv):
|
||||||
|
parser = argparse.ArgumentParser(description=__doc__)
|
||||||
|
|
||||||
|
parser.add_argument('keyword')
|
||||||
|
parser.set_defaults(func=inputrename_argparse)
|
||||||
|
|
||||||
|
args = parser.parse_args(argv)
|
||||||
|
return args.func(args)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
try:
|
||||||
|
raise SystemExit(main(sys.argv[1:]))
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
raise SystemExit(1)
|
||||||
|
|
Loading…
Reference in a new issue