1

I want to rename the below files, such that the first 4 chars and last 7 chars are removed, the remaining chars to be converted to decimal, while rename.

Example if the filename is 0030002345678.txt, should be renamed to 00.txt(removing the chars and converting to hex).

If it is 00300A2345678.txt, should be renamed to 10.txt(after conversion from hex of '0A'

1

What about this:

ls | python -c 'import sys, os; print len([os.system("mv %s %02i.%s" % (name[:-1], int(name.split(".")[0][4:-7], 16), name.split(".")[1])) for name in sys.stdin])'

Assumes the files to be renamed are exactly those that ls would print; supply anything more relevant, if this is not the case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.