List of usage examples for java.io File isHidden
public boolean isHidden()
From source file:com.example.lista3new.MainActivity.java
/** Loads file list from sdcard, and adds them to ListView */ private void loadFiles() { mCurrentDirectoryInfo.setText(currentPath.getPath()); FilenameFilter fileFilter = new FilenameFilter() { @Override/*from w ww . jav a 2 s . c o m*/ public boolean accept(File dir, String filename) { File sel = new File(dir, filename); return (sel.isFile() && !sel.isHidden()); } }; FilenameFilter dirFilter = new FilenameFilter() { @Override public boolean accept(File dir, String filename) { File sel = new File(dir, filename); return (sel.isDirectory() && !sel.isHidden()); } }; Log.d(TAG, "path: " + currentPath.getPath()); String[] fList = currentPath.list(fileFilter); String[] dirList = currentPath.list(dirFilter); Log.d(TAG, "fList length: " + String.valueOf(fList.length)); Log.d(TAG, "dirList length: " + String.valueOf(dirList.length)); Log.d(TAG, "created file list"); mFileList = new ArrayList<Item>(); for (int i = 0; i < dirList.length; ++i) { mFileList.add(new Item(dirList[i], SyncService.DIR_TYPE)); } for (int i = 0; i < fList.length; ++i) { mFileList.add(new Item(fList[i], SyncService.FILE_TYPE)); } mAdapter = new ImageAdapter(this, mFileList); mFileListView.setAdapter(mAdapter); }
From source file:com.all.login.LoginModule.java
private boolean isCleanInstallation(File f) { if (f.isFile() && !f.isHidden()) { return false; }/*from w w w . j a v a 2 s . com*/ if (f.isDirectory()) { for (File f2 : f.listFiles()) { if (!isCleanInstallation(f2)) { return false; } } } return true; }
From source file:ch.admin.suis.msghandler.signer.SignerTest.java
private List<File> getAllFilesFromDir(File directory) { if (directory == null) { return new ArrayList<File>(); }/*from ww w . j av a 2s.c om*/ File[] files = ch.admin.suis.msghandler.util.FileUtils.listFiles(directory, new FileFilter() { @Override public boolean accept(File pathname) { return pathname.isFile() && ch.admin.suis.msghandler.util.FileUtils.canRead(pathname) && !pathname.isHidden(); } }); List<File> retVal = new ArrayList(); Collections.addAll(retVal, files); return retVal; }
From source file:ie.programmer.catcher.browser.FileBrowserEngine.FileBrowserEngine.java
/** * Loads the specified folder.//from w w w.j a v a 2 s . c om * * @param directory The file object to points to the directory to load. * @return An {@link AdapterData} object that holds the data of the specified directory. */ public AdapterData loadDir(File directory) { mCurrentDir = directory; //Init the directory's data arrays. ArrayList<String> namesList = new ArrayList<String>(); ArrayList<String> pathsList = new ArrayList<String>(); ArrayList<Integer> typesList = new ArrayList<Integer>(); ArrayList<String> sizesList = new ArrayList<String>(); //Grab a list of all files/subdirs within the specified directory. File[] files = directory.listFiles(); if (files != null) { //Sort the files/subdirs by name. Arrays.sort(files, NameFileComparator.NAME_INSENSITIVE_COMPARATOR); for (int i = 0; i < files.length; i++) { File file = files[i]; if ((!file.isHidden() || mFileBrowserView.shouldShowHiddenFiles()) && file.canRead()) { if (file.isDirectory() && mFileBrowserView.shouldShowFolders()) { /* * Starting with Android 4.2, /storage/emulated/legacy/... * is a symlink that points to the actual directory where * the user's files are stored. We need to detect the * actual directory's file path here. */ String filePath; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) filePath = getRealFilePath(file.getAbsolutePath()); else filePath = file.getAbsolutePath(); pathsList.add(filePath); namesList.add(file.getName()); File[] listOfFiles = file.listFiles(); if (listOfFiles != null) { typesList.add(FOLDER); if (listOfFiles.length == 1) { sizesList.add("" + listOfFiles.length + " item"); } else { sizesList.add("" + listOfFiles.length + " items"); } } else { typesList.add(FOLDER); sizesList.add("Unknown items"); } } else { try { String path = file.getCanonicalPath(); if (isFilteredFile(path)) { continue; } pathsList.add(path); } catch (Exception e) { Log.e("File Error", e.getMessage()); continue; } namesList.add(file.getName()); String fileName = ""; try { fileName = file.getCanonicalPath(); } catch (IOException e) { e.printStackTrace(); } //Add the file element to typesList based on the file type. if (getFileExtension(fileName).equalsIgnoreCase("mp3") || getFileExtension(fileName).equalsIgnoreCase("3gp") || getFileExtension(fileName).equalsIgnoreCase("mp4") || getFileExtension(fileName).equalsIgnoreCase("m4a") || getFileExtension(fileName).equalsIgnoreCase("aac") || getFileExtension(fileName).equalsIgnoreCase("ts") || getFileExtension(fileName).equalsIgnoreCase("flac") || getFileExtension(fileName).equalsIgnoreCase("mid") || getFileExtension(fileName).equalsIgnoreCase("xmf") || getFileExtension(fileName).equalsIgnoreCase("mxmf") || getFileExtension(fileName).equalsIgnoreCase("midi") || getFileExtension(fileName).equalsIgnoreCase("rtttl") || getFileExtension(fileName).equalsIgnoreCase("rtx") || getFileExtension(fileName).equalsIgnoreCase("ota") || getFileExtension(fileName).equalsIgnoreCase("imy") || getFileExtension(fileName).equalsIgnoreCase("ogg") || getFileExtension(fileName).equalsIgnoreCase("mkv") || getFileExtension(fileName).equalsIgnoreCase("wav")) { //The file is an audio file. typesList.add(FILE_AUDIO); sizesList.add("" + getFormattedFileSize(file.length())); } else if (getFileExtension(fileName).equalsIgnoreCase("jpg") || getFileExtension(fileName).equalsIgnoreCase("gif") || getFileExtension(fileName).equalsIgnoreCase("png") || getFileExtension(fileName).equalsIgnoreCase("bmp") || getFileExtension(fileName).equalsIgnoreCase("webp")) { //The file is a picture file. typesList.add(FILE_PICTURE); sizesList.add("" + getFormattedFileSize(file.length())); } else if (getFileExtension(fileName).equalsIgnoreCase("3gp") || getFileExtension(fileName).equalsIgnoreCase("mp4") || getFileExtension(fileName).equalsIgnoreCase("3gp") || getFileExtension(fileName).equalsIgnoreCase("ts") || getFileExtension(fileName).equalsIgnoreCase("webm") || getFileExtension(fileName).equalsIgnoreCase("mkv")) { //The file is a video file. typesList.add(FILE_VIDEO); sizesList.add("" + getFormattedFileSize(file.length())); } else { //We don't have an icon for this file type so give it the generic file flag. typesList.add(FILE_GENERIC); sizesList.add("" + getFormattedFileSize(file.length())); } } } } } return new AdapterData(namesList, typesList, pathsList, sizesList); }
From source file:com.aniruddhc.acemusic.player.MusicFoldersSelectionFragment.MusicFoldersSelectionFragment.java
/** * Retrieves the folder hierarchy for the specified folder * (this method is NOT recursive and doesn't go into the parent * folder's subfolders. //from w w w.j av a2 s .com */ private void getDir(String dirPath) { mFileFolderNamesList = new ArrayList<String>(); mFileFolderPathsList = new ArrayList<String>(); mFileFolderSizesList = new ArrayList<String>(); File f = new File(dirPath); File[] files = f.listFiles(); Arrays.sort(files); if (files != null) { for (int i = 0; i < files.length; i++) { File file = files[i]; if (!file.isHidden() && file.canRead()) { if (file.isDirectory()) { /* * Starting with Android 4.2, /storage/emulated/legacy/... * is a symlink that points to the actual directory where * the user's files are stored. We need to detect the * actual directory's file path here. */ String filePath; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) filePath = getRealFilePath(file.getAbsolutePath()); else filePath = file.getAbsolutePath(); mFileFolderPathsList.add(filePath); mFileFolderNamesList.add(file.getName()); File[] listOfFiles = file.listFiles(); if (listOfFiles != null) { if (listOfFiles.length == 1) { mFileFolderSizesList.add("" + listOfFiles.length + " item"); } else { mFileFolderSizesList.add("" + listOfFiles.length + " items"); } } } } } } boolean dirChecked = false; if (getMusicFoldersHashMap().get(dirPath) != null) dirChecked = getMusicFoldersHashMap().get(dirPath); MultiselectListViewAdapter mFoldersListViewAdapter = new MultiselectListViewAdapter(getActivity(), this, mWelcomeSetup, dirChecked); mFoldersListView.setAdapter(mFoldersListViewAdapter); mFoldersListViewAdapter.notifyDataSetChanged(); mCurrentDir = dirPath; setCurrentDirText(); }
From source file:com.sangupta.httpd.HttpdHandler.java
/** * Send directory listing back to client * /*w w w .jav a2 s .co m*/ * @param response * @param dir * @throws IOException */ private void showDirectoryListing(HttpServletResponse response, File dir) throws IOException { StringBuilder buf = new StringBuilder(); String dirName = dir.getAbsoluteFile().getName(); if (AssertUtils.isEmpty(dirName)) { dirName = dir.getAbsoluteFile().getParentFile().getName(); } buf.append("<!DOCTYPE html>\r\n"); buf.append("<html><head><title>"); buf.append("Listing of: "); buf.append(dirName); buf.append("</title></head><body>\r\n"); buf.append("<h3>Listing of: "); buf.append(dirName); buf.append("</h3>\r\n"); buf.append("<ul>"); buf.append("<li><a href=\"../\">..</a></li>\r\n"); for (File f : dir.listFiles()) { if (f.isHidden() || !f.canRead()) { continue; } String name = f.getName(); if (!ALLOWED_FILE_NAME.matcher(name).matches()) { continue; } buf.append("<li><a href=\""); buf.append(name); buf.append("\">"); buf.append(name); buf.append("</a></li>\r\n"); } buf.append("</ul></body></html>\r\n"); byte[] bytes = buf.toString().getBytes(StringUtils.CHARSET_UTF8); response.setHeader("Content-Type", "text/html; charset=UTF-8"); response.setCharacterEncoding("UTF-8"); response.setContentLength(bytes.length); response.getOutputStream().write(bytes); }
From source file:ro.ieugen.fileserver.http.HttpStaticFileServerHandler.java
@Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { HttpRequest request = (HttpRequest) e.getMessage(); final String path = sanitizeUri(request.getUri()); LOG.info("Requested URI is {}, sanitised path is {}", request.getUri(), path); if (path == null) { sendError(ctx, FORBIDDEN);//from www . j ava 2 s . co m return; } File file = new File(path); if (file.isHidden() || !file.exists()) { sendError(ctx, NOT_FOUND); return; } if (!(file.isFile() || file.isDirectory())) { sendError(ctx, FORBIDDEN); return; } Channel ch = e.getChannel(); ChannelFuture writeFuture = null; if (file.isDirectory()) { ch.write(directoryListingResponse(file)); } else { // Cache Validation if (sendRetrieveFromCacheIfNotModified(ctx, request, file)) return; RandomAccessFile raf = openFileOrSendError(ctx, file); if (raf == null) return; // Write the initial line and the header. ch.write(fileDownloadResponse(file, raf)); // Write the content. if (ch.getPipeline().get(SslHandler.class) != null) { // Cannot use zero-copy with HTTPS. writeFuture = ch.write(new ChunkedFile(raf, 0, raf.length(), 8192)); } else { // No encryption - use zero-copy. final FileRegion region = new DefaultFileRegion(raf.getChannel(), 0, raf.length()); writeFuture = ch.write(region); writeFuture.addListener(new ChannelFutureProgressListener() { public void operationComplete(ChannelFuture future) { region.releaseExternalResources(); } public void operationProgressed(ChannelFuture future, long amount, long current, long total) { LOG.info("{}", String.format("%s: %d / %d (+%d)%n", path, current, total, amount)); } }); } } // Decide whether to close the connection or not. if (!isKeepAlive(request)) { // Close the connection when the whole content is written out. writeFuture.addListener(ChannelFutureListener.CLOSE); } }
From source file:org.geotools.coverage.io.util.Utilities.java
/** * Creates a human readable message that describe the provided {@link File} object in terms of its properties. * //from w ww. j a v a 2s . com * <p> * Useful for creating meaningful log messages. * * @param file the {@link File} object to create a descriptive message for * @return a {@link String} containing a descriptive message about the provided {@link File}. * */ public static String getFileInfo(final File file) { final StringBuilder builder = new StringBuilder(); builder.append("Checking file:").append(FilenameUtils.getFullPath(file.getAbsolutePath())).append("\n"); builder.append("isHidden:").append(file.isHidden()).append("\n"); builder.append("exists:").append(file.exists()).append("\n"); builder.append("isFile").append(file.isFile()).append("\n"); builder.append("canRead:").append(file.canRead()).append("\n"); builder.append("canWrite").append(file.canWrite()).append("\n"); builder.append("canExecute:").append(file.canExecute()).append("\n"); builder.append("isAbsolute:").append(file.isAbsolute()).append("\n"); builder.append("lastModified:").append(file.lastModified()).append("\n"); builder.append("length:").append(file.length()); final String message = builder.toString(); return message; }
From source file:it.readbeyond.minstrel.librarian.Librarian.java
private void discoverPublicationFiles(File rootDirectory, FormatHandler fh, List<Publication> publications, FileFilter directoryFilter, FileFilter fileFilter) { boolean ignoreHidden = true; // TODO boolean recursive = true; // TODO File[] dirs = rootDirectory.listFiles(directoryFilter); for (File d : dirs) { if ((recursive) && (d.canRead()) && (!d.isHidden())) { discoverPublicationFiles(d, fh, publications, directoryFilter, fileFilter); }/* w w w . jav a 2 s .co m*/ } File[] files = rootDirectory.listFiles(fileFilter); for (File f : files) { String n = f.getName(); if ((!((ignoreHidden) && (n.startsWith(".")))) && (fh.isParsable(n.toLowerCase()))) { discoverSingleFile(f, fh, publications); } } }
From source file:org.estatio.dscm.services.SyncService.java
private List<File> filesForFolder(final File folder) { List<File> fileList = new ArrayList<File>(); for (final File file : folder.listFiles()) { if (file.isFile() && !file.isHidden()) { fileList.add(file);//w w w. j a v a2 s . co m } } return fileList; }