在缺少前导零后撤消错误排序
Undo wrong sorting after missing leading zeros
这里有一个小谜语,想花点时间看的人:
我有大约 200 个文件由于缺少前导零而排序和重命名不当。我必须撤消排序,并再次分配原始值,这样我就有了这样的顺序:
current file name original
TimePoint1 -> TimePoint1
TimePoint2 -> TimePoint10
TimePoint3 -> TimePoint100
TimePoint4 -> TimePoint101
TimePoint5 -> TimePoint102
...
TimePoint250 -> TimePoint250
我会努力寻找答案,但我不想错过您可能提供的任何优雅解决方案。
谢谢,玩得开心!
这里只是按字母顺序排列。因此,取消排序的最简单方法是再次使用此顺序。我不确定您要使用哪种语言,所以这里是 ruby:
中的示例
a = []
(1..250).each{|t| a << t.to_s} # note that I am adding the *string* representation
a.sort!
(0...250).each do |i|
File.rename("TimePoint#{a[i]}", "TimePoint#{i + 1}")
end
这里有一个小谜语,想花点时间看的人:
我有大约 200 个文件由于缺少前导零而排序和重命名不当。我必须撤消排序,并再次分配原始值,这样我就有了这样的顺序:
current file name original
TimePoint1 -> TimePoint1
TimePoint2 -> TimePoint10
TimePoint3 -> TimePoint100
TimePoint4 -> TimePoint101
TimePoint5 -> TimePoint102
...
TimePoint250 -> TimePoint250
我会努力寻找答案,但我不想错过您可能提供的任何优雅解决方案。
谢谢,玩得开心!
这里只是按字母顺序排列。因此,取消排序的最简单方法是再次使用此顺序。我不确定您要使用哪种语言,所以这里是 ruby:
中的示例a = []
(1..250).each{|t| a << t.to_s} # note that I am adding the *string* representation
a.sort!
(0...250).each do |i|
File.rename("TimePoint#{a[i]}", "TimePoint#{i + 1}")
end