List of usage examples for java.io File isHidden
public boolean isHidden()
From source file:adalid.commons.util.FilUtils.java
public static boolean isVisibleFile(File file) { return file != null && file.isFile() && !file.isHidden(); }
From source file:adalid.commons.util.FilUtils.java
public static boolean isVisibleDirectory(File file) { return file != null && file.isDirectory() && !file.isHidden(); }
From source file:org.danilopianini.io.FileUtilities.java
/** * Tests whether or not any parent of the given file is hidden. * /* www. j ava2s . c o m*/ * @param file * the file to test * @return true if at least one of the parent directories is hidden */ public static boolean isInHiddenPath(final File file) { boolean hidden = false; File f = file; do { hidden = f.isHidden(); f = f.getParentFile(); } while (!(hidden || f == null)); return hidden; }
From source file:com.redhat.rhn.domain.kickstart.cobbler.CobblerSnippet.java
private static void validateCommonPath(File path) { if (!path.exists() || path.isHidden() || !path.isFile() || !isCommonPath(path) || path.getAbsolutePath().contains("\"") || path.getAbsolutePath().contains("&")) { ValidatorException.raiseException("cobbler.snippet.invalidfilename.message"); }//from ww w . j a va2s . c om }
From source file:org.apache.hadoop.hive.ql.metadata.JarUtils.java
private static void zipDir(File dir, String relativePath, ZipOutputStream zos, boolean start) throws IOException { String[] dirList = dir.list(); for (String aDirList : dirList) { File f = new File(dir, aDirList); if (!f.isHidden()) { if (f.isDirectory()) { if (!start) { ZipEntry dirEntry = new ZipEntry(relativePath + f.getName() + "/"); zos.putNextEntry(dirEntry); zos.closeEntry();// w w w .ja v a2 s .com } String filePath = f.getPath(); File file = new File(filePath); zipDir(file, relativePath + f.getName() + "/", zos, false); } else { String path = relativePath + f.getName(); if (!path.equals(JarFile.MANIFEST_NAME)) { ZipEntry anEntry = new ZipEntry(path); InputStream is = new FileInputStream(f); copyToZipStream(is, anEntry, zos); } } } } }
From source file:de.petermoesenthin.alarming.util.FileUtil.java
/** * Returns a file list of all non-hidden audio files in the application directory. * * @return/*from www .j a v a 2s. c o m*/ */ public static File[] getAlarmDirectoryAudioFileList(final Context context) { return FileUtil.getApplicationDirectory().listFiles(new FileFilter() { @Override public boolean accept(File f) { // Early out if hidden if (f.isHidden()) { return false; } String extension = FilenameUtils.getExtension(f.getPath()); if (extension.equals(AUDIO_METADATA_FILE_EXTENSION)) { return false; } return fileIsOK(context, f.getPath()); } }); }
From source file:org.entrystore.repository.backup.BackupJob.java
synchronized public static void runBackupMaintenance(JobExecutionContext jobContext) throws Exception { if (interrupted) { return;/* ww w.j a v a2s .c o m*/ } log.info("Starting backup maintenance job"); JobDataMap dataMap = jobContext.getJobDetail().getJobDataMap(); RepositoryManagerImpl rm = (RepositoryManagerImpl) dataMap.get("rm"); int upperLimit = (Integer) dataMap.get("upperLimit"); int lowerLimit = (Integer) dataMap.get("lowerLimit"); int expiresAfterDays = (Integer) dataMap.get("expiresAfterDays"); log.info("upperlimit: " + upperLimit + ", lowerLimit: " + lowerLimit + ", expiresAfterDays: " + expiresAfterDays); String exportPath = rm.getConfiguration().getString(Settings.BACKUP_FOLDER); Date today = new Date(); if (exportPath == null) { log.error("Unknown backup path, please check the following setting: " + Settings.BACKUP_FOLDER); } else { File backupFolder = new File(exportPath); DateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss"); List<Date> backupFolders = new ArrayList<Date>(); for (File file : backupFolder.listFiles()) { if (!file.isDirectory() || file.isHidden()) { log.info("Ignoring: " + file); continue; } try { Date date = formatter.parse(file.getName()); backupFolders.add(date); log.info("Found backup folder: " + file); } catch (ParseException pe) { log.warn("Skipping path: " + file + ". Reason: " + pe.getMessage()); continue; } } if (backupFolders.size() <= lowerLimit) { log.info("Lower limit not reached - backup maintenance job done with execution"); return; } Collections.sort(backupFolders, new Comparator<Date>() { public int compare(Date a, Date b) { if (a.after(b)) { return 1; } else if (a.before(b)) { return -1; } else { return 0; } } }); if (backupFolders.size() > upperLimit) { int nrRemoveItems = backupFolders.size() - upperLimit; log.info("Upper limit is " + upperLimit + ", will delete " + nrRemoveItems + " backup folder(s)"); for (int i = 0; i < nrRemoveItems; i++) { String folder = formatter.format(backupFolders.get(i)); File f = new File(exportPath, folder); if (deleteDirectory(f)) { backupFolders.remove(i); log.info("Deleted " + f); } else { log.info("Unable to delete " + f); } } } Date oldestDate = backupFolders.get(0); if (daysBetween(oldestDate, today) > expiresAfterDays) { for (int size = backupFolders.size(), i = 0; lowerLimit < size; size--) { Date d = backupFolders.get(i); if (daysBetween(d, today) > expiresAfterDays) { String folder = formatter.format(backupFolders.get(i)); File f = new File(exportPath, folder); if (deleteDirectory(f)) { backupFolders.remove(i); log.info("Deleted " + f); } else { log.info("Unable to delete " + f); } } else { break; } } } } log.info("Backup maintenance job done with execution"); }
From source file:uk.ac.ebi.metabolights.utils.Zipper.java
private static void addFilesToZip(ZipOutputStream zout, File[] files, String innerFolder) throws IOException { // Loop through the list of files to zip for (int i = 0; i < files.length; i++) { File file = files[i]; //If the directory is hidden...it is zipping the svn folders.. if (file.isHidden()) { System.out.println("Skiping hidden file " + file.getName()); continue; }//from w w w .j a va 2 s . c om //if the file is directory, call the function recursively if (file.isDirectory()) { //get sub-folder/files list File[] files2 = file.listFiles(); addFilesToZip(zout, files2, innerFolder + file.getName() + "/"); continue; } /* * if we are here, it means, it's a file and not directory, so * add it to the zip file */ try { System.out.println("Adding file " + file.getName()); //create byte buffer byte[] buffer = new byte[1024]; //create object of FileInputStream FileInputStream fin = new FileInputStream(file); zout.putNextEntry(new ZipEntry(innerFolder + file.getName())); /* * After creating entry in the zip file, actually * write the file. */ int length; while ((length = fin.read(buffer)) > 0) { zout.write(buffer, 0, length); } /* * After writing the file to ZipOutputStream, use * * void closeEntry() method of ZipOutputStream class to * close the current entry and position the stream to * write the next entry. */ zout.closeEntry(); //close the InputStream fin.close(); } catch (IOException ioe) { System.out.println("IOException :" + ioe); throw ioe; } } }
From source file:com.aliyun.odps.local.common.utils.LocalRunUtils.java
private static void listEmptyDirectory(File dir, List<File> dataFiles) { if (!dir.isDirectory()) { return;//ww w .ja v a 2 s. co m } File[] subDirs = dir.listFiles(new FileFilter() { @Override public boolean accept(File pathname) { return !pathname.isHidden(); } }); if (subDirs.length == 0) { System.out.println(dir.getAbsolutePath()); dataFiles.add(dir); return; } for (File f : subDirs) { if (f.isDirectory()) { listEmptyDirectory(f, dataFiles); } } }
From source file:uk.ac.ebi.metabolights.webservice.utils.FileUtil.java
/** * Get a list of files in the private FTP folder * * @param ftpFolder//from ww w . j a v a 2 s . c o m * @return * @author jrmacias * @date 20151102 */ public static String[] getFtpFolderList(String ftpFolder) { File[] files = new File(ftpFolder).listFiles(new FileFilter() { @Override public boolean accept(File file) { return !file.isHidden(); } }); List<String> fileNames = new ArrayList<>(); for (File file : files) { fileNames.add(file.getName()); } String[] names = new String[fileNames.size()]; return fileNames.toArray(names); }