Get directory list sorted by size

P

POM

Posit:

I want to retrieve a directory listing (of images) on a UNIX server,
sorted by size (in descending order). I wanted to just write a simple
runtime process exec to do the job... something like this:

Process p =
Runtime.getRuntime().exec("/bin/ls -l /images | sort +4nr");

But then I saw somewhere that it will parse the exec arguments as
separate commands. Anybody have an idea that will return the desired
results.

Thanks.
 
C

Christophe Vanfleteren

POM said:
Posit:

I want to retrieve a directory listing (of images) on a UNIX server,
sorted by size (in descending order). I wanted to just write a simple
runtime process exec to do the job... something like this:

Process p =
Runtime.getRuntime().exec("/bin/ls -l /images | sort +4nr");

But then I saw somewhere that it will parse the exec arguments as
separate commands. Anybody have an idea that will return the desired
results.

Thanks.

Look at File.listFiles(), File.length(), Arrays.sort() and Comparator.
 
S

Sudsy

POM said:
Posit:

I want to retrieve a directory listing (of images) on a UNIX server,
sorted by size (in descending order).
But then I saw somewhere that it will parse the exec arguments as
separate commands. Anybody have an idea that will return the desired
results.

This should do what you want:

Process p = Runtime.getRuntime().exec(
new String[] { "/bin/ls", "-lS", "/images" } );

(note the -S flag: sort by size)
 
A

Andrew Thompson

Process p = Runtime.getRuntime().exec(
new String[] { "/bin/ls", "-lS", "/images" } );

Not if he's running windows!

(quoted from earlier in thread..)
"I want to retrieve a directory listing
(of images) on a UNIX server,.."
 
S

Sudsy

Roedy said:
Process p = Runtime.getRuntime().exec(
new String[] { "/bin/ls", "-lS", "/images" } );


Not if he's running windows!

But if that were the case then OP wouldn't have provided /bin/ls as
the executable in the first place, c'nest pas?
 
A

Andrew Thompson

Process p = Runtime.getRuntime().exec(
new String[] { "/bin/ls", "-lS", "/images" } );

Not if he's running windows!

(quoted from earlier in thread..)
"I want to retrieve a directory listing
(of images) on a UNIX server,.."

I checked the OP when I writ that,
though now I notice it was *requoted*
in Sudsy's post as well.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top