-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsortFilesRecursively
More file actions
63 lines (59 loc) · 1.7 KB
/
Copy pathsortFilesRecursively
File metadata and controls
63 lines (59 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/ ************** Java Program To Implement ls -lR | egrep "txt$|tab$"|sort -nr+4 | tail + | head -5 ****************/
package com.listfiles.list;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public class LsImpl {
/** * @param args */
@SuppressWarnings("unchecked") public static void main(String[] args) {
// TODO Auto-generated method stub File file = new File("/home");
List<File> filelist = new ArrayList<File>();
List<File> fls = getfilesrecurse(file, filelist);
Collections.sort(fls , new Comparator()
Object file2) { ((File)file2).length())
((File)file2).length())
if(((File)file1).length() <
return 1; if(((File)file1).length() >
{
});
@Override public int compare(Object file1,
}
else
return -1; return 0;
//for(File file2 : fls) for(int i=4; i<9 ; i++) {
File fileopt = fls.get(i); if(fileopt.isDirectory())
System.out.print("d");
else
System.out.print("-"); if(fileopt.canRead())
System.out.print("r");
else
System.out.print("-"); if(fileopt.canWrite())
System.out.print("w");
else
System.out.print("-"); if(fileopt.canExecute())
System.out.print("x");
else
System.out.print("-"); System.out.print(" " +fileopt.length() + " "+
fileopt.lastModified() +" "+fileopt.getName()+"\n"); }
}
private static List<File> getFilesRecurse(File folder , List<File> filelist)
{
file.getName().endsWith("tab"))
}
else
if(file.getName().endsWith("txt") || {
filelist.add(file); getFilesRecurse(file,filelist);
for(File file : folder.listFiles()) {
if(file.isDirectory()) {
}
if(!file.getName().startsWith(".") && (file.getName (). endsWith("txt") || file.getName(). endsWith("tab")))
{
filelist.add(file);
return filelist;
}
}
}
}