For example, if for some reason you wanted filenames like AS00000000000001.txt, you would replace %02d with %014d. If you want to pad to a greater width than 2, replace the 2 with a bigger number. ![]() You can modify them as needed, then only remove -n when you like what you see. As written, this would produce the filenames AS01.txt, AS02.txt. Once you try one out and you're happy with the results, run it again without the -n option. Each shows what renaming operations would be undertaken. (It could be made even shorter, but not without sacrificing clarity.)īoth those commands do the same thing. ![]() Or, if you feel like shaving off a few characters: rename -n '$_ = sprintf "AS%02d.txt", ++our$i' * I suggest using a command like this: rename -n 'our $i $_ = sprintf "AS%02d.txt", ++$i' * rename lets you write just about any Perl code, and it doesn't need to be embedded inside s/ /e. Rename lets you assign directly to $_, which is ideal for this problem.Īlthough the code arguments we pass to the Perl rename utility often perform matching and substitution (with s/), and it is totally acceptable to solve this problem that way, there's really no need for that in cases like this one where you're not actually examining or reusing the text of the old filenames.
0 Comments
Leave a Reply. |