Take the 2-minute tour ×
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
2  
@nXqd see tags. –  John T Jan 7 '11 at 3:08
add comment

3 Answers 3

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

#!C:/Perl/bin/perl.exe
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;

foreach(@a)
{
    print "$_\n" if -f;
}

output:

p.pl
p.php
lwp.pl
test.bat
index.htm
index.php
readnsort.pl
scrape_parse.txt
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
add comment

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
add comment

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
add comment

Your Answer

 
discard

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.