package filesystem; import java.io.File; import java.util.ArrayList; /** * * @author ablackbu * */ public class FSInfo { //singelton private static FSInfo instance; // User's home directory. private String homeDir; // Current working directory private String currentWorkingDir; // user name private String userName; // operating system name private String operatingSys; // temporary directory private String tempDir; // the java class path private String classPath; //the list of sub directories in the - including hidden files private ArrayList subDirs; //the list of all files in the directory - including hidden files private ArrayList files; //the list of sub directories in the - excluding hidden files private ArrayList nonHiddenSubDirs; //the list of sub directories in the - excluding hidden files private ArrayList nonHiddenFiles; // the current file or directory //File file; private FSInfo() { homeDir = System.getProperty("user.home"); currentWorkingDir = System.getProperty("user.dir"); userName = System.getProperty("user.name"); operatingSys = System.getProperty("os.name"); tempDir = System.getProperty("java.io.tmpdir"); classPath = System.getProperty("java.class.path"); subDirs = new ArrayList(); files = new ArrayList(); nonHiddenSubDirs = new ArrayList(); nonHiddenFiles = new ArrayList(); switchDir(homeDir); } /** * Public access for the singleton. * * @return the singleton object. */ public static FSInfo getInstance() { if (instance == null) { instance = new FSInfo(); } return instance; } /** * * @param newDir */ public void switchDir(String newDir) { File file = new File(newDir); File[] f = file.listFiles(); for(int i = 0; i < f.length; ++i) { if(f[i].isFile()) { files.add(f[i]); if(!f[i].isHidden()) { nonHiddenFiles.add(f[i]); } } else { subDirs.add(f[i]); if(!f[i].isHidden()) { nonHiddenSubDirs.add(f[i]); } } } } public ArrayList getSubDirs() { return subDirs; } public ArrayList getNonHiddenSubDirs() { return nonHiddenSubDirs; } public ArrayList getFiles() { return files; } public ArrayList getNonHiddenFiles() { return nonHiddenFiles; } public String getOS() { return operatingSys; } public String getClasspath() { return classPath; } public String getTempDir() { return tempDir; } public String getUserName() { return userName; } public String getCurrentWorkingDir() { return currentWorkingDir; } public String getHomeDir() { return homeDir; } }