-
-
Save 6LYTH3/1103450 to your computer and use it in GitHub Desktop.
command package
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_); | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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