Skip to content

Instantly share code, notes, and snippets.

@6LYTH3
Forked from wingyplus/find.java
Created July 25, 2011 02:43
Show Gist options
  • Save 6LYTH3/1103450 to your computer and use it in GitHub Desktop.
Save 6LYTH3/1103450 to your computer and use it in GitHub Desktop.
command package
package command;
import java.io.File;
public class find {
public static void main(String[] args) {
if (args.length == 0) System.out.println("please input path ...");
else {
find(args[0]);
}
}
private static void find(String item) {
File dir = new File("./");
String[] list = dir.list();
for (String list_ : list) {
if (list_.equals(item)) {
System.out.println(list_);
showPath(list_);
}
}
}
private static void showPath(String path) {
File dir = new File(path);
if (dir.isFile()) {}
else {
String[] list = dir.list();
for (String list_ : list) {
File item = new File(path + "/" + list_);
if (item.isDirectory()) list_ = list_ + File.separator;
System.out.println(path + "/" + list_);
}
}
}
}
package command;
import java.io.File;
public class ls {
public static void main(String[] args) {
if (args.length == 0) dirlist(".");
else {
dirlist(args[0]);
}
}
private static void dirlist(String path) {
File dir = new File(path);
String[] list = dir.list();
try { System.out.println("List of " + dir.getCanonicalPath()); } catch (Exception e) { System.out.println("Error: "+e.getMessage()); }
for (String list_ : list) {
File isDir = new File(path + "/" + list_);
if (isDir.isDirectory()) list_ = list_ + File.separator;
System.out.println(list_);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment