-2
I have a list of images grouped numerically (YI0.png
, YI1.png
...YI20479.png
). I want them sorted alphabetically, like so:
YI0.png -> YIA.png
YI1.png -> YIAA.png
without my last image having 20479 A
s in it.
Input
A directory name.
Output
All files in that directory will be alphabetically renamed.
Constraints
- The pattern is always
Prefix
Number
.Extension
- There are no subdirectories
- All files in the directory adhere to the pattern
Number
starts at 0Prefix
doesn't contain numbers
Example
Directory consisting of Pie0.txt
, Pie1.txt
, all the way to Pie11.txt
would be renamed to PieA.txt
, PieB.txt
, all the way to PieL.txt
.
If it goes to Pie28.txt
, they would be renamed like so:
Pie0.txt -> PieA.txt
Pie1.txt -> PieAA.txt
Pie2.txt -> PieAB.txt
Pie3.txt -> PieB.txt
Pie28.txt -> PieZ.txt
Remember, this is code-golf, so the answer in the shortest bytes wins.
will all files in the dir be of the form
"some_letters_that_are_always_the_sameNumber.txt"
? – Maltysen – 2016-09-05T16:19:23.553Yes, it will have a pattern of
PrefixNumber.Extension
@Maltysen – Soren – 2016-09-05T16:20:48.580will be ever have three length codes? – Maltysen – 2016-09-05T16:37:50.920
Will the directory only have plain files or can it e.g. have subdirectories which need to be ignored or recursed into ? – Ton Hospel – 2016-09-05T17:10:58.867
Anyways, I'm not sure I like a challenge that needs to do system commands and especially filename parsing (e.g. is
\\
or/
the separator, can files start with.
etc.) . An input that is a list of simple filenames with an output that are the corresponding translated names seems nicer to me – Ton Hospel – 2016-09-05T17:14:54.293Can there be holes in the sequence of numbers ? Can numbers have extra leading zeros ? Can the prefix contain digits ? Does the sequence always start with
0
? – Ton Hospel – 2016-09-05T17:19:19.960Yes, there will be varied length codes (remember, I have 20479 files). The prefix and extension will only contain alphabetical characters. There are no subdirectories or different patterned files. – Soren – 2016-09-05T17:37:28.407
Will the numeric suffix have leading zeroes? If you sort the numbers between 1 and 100 alphabetically you get [1, 10, 100, 11, 12 ..], but if they have leading zeroes you get [001, 002, 003 ..] – BlackCap – 2016-09-05T18:07:06.610
@BlackCap they do not – Soren – 2016-09-05T18:10:07.803
Since there are different OS in the world, can we not write a program or function which takes a list of strings in the format you defined and outputs a list of new names in the same order as the input list such that the output list is in alphabetic order? Also can we use digits and lowercase letters in our new names (since standard alphabetic sorting would be 0<9<A<Z<a<z)? – Jonathan Allan – 2016-09-05T18:52:30.610
1@Jonathan Allan only letters, not numbers. Lowercase and uppercase are allowed though. – Soren – 2016-09-05T18:53:41.023
2This needs a spec. At present we have to guess what it might be from two examples. – Peter Taylor – 2016-09-05T21:20:32.850
Imagine a hyperdictionary but culled to only have the amount of "words" as the numbers. Once I run the perl example I will have more examples – Soren – 2016-09-05T22:02:11.950