Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .