Sign up ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Can I sort files according to the length of filename?

share|improve this question
you should provide your platform ? – nXqd Jan 7 '11 at 3:06
@nXqd see tags. – John T Jan 7 '11 at 3:08

3 Answers 3

If you just want the list of filenames, you can do it easily with excel. Or you can do it with FileBoss . Windows-explorer can't do this :)

share|improve this answer

Since you haven't specified a preferred method, here is a solution in Perl:

use strict;
use warnings;

my @a;

opendir(my $dir, ".") or die $!;
while(readdir $dir) {
    push @a, $_;
closedir $dir;

@a = sort { length($a) <=> length($b) } @a;

    print "$_\n" if -f;

share|improve this answer
You can use readdir() in a list context - the while loop is unnecessary. (Spaghetti Perl mode: $\ = "\n"; print if -f for sort {length($a) <=> length($b)} readdir $dir;) – grawity Jan 7 '11 at 6:14

Output the contents of a folder, sorted by file name length using PowerShell:

 gci c:\anyfolder | select-object name, @{Name="Nlength";Expression={$_.Name.Length}} | sort-object Nlength

It'll output something like this:

Name                     Nlength
----                     -------
DL.mdb                         6
trolol.txt                    10
AAAAA-2011-03-23-111.xls      24
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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