Java Code Examples for java.io.File.isHidden()

The following are Jave code examples for showing how to use isHidden() of the java.io.File class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: stynico   File: Util.java   View Source Code Vote up 6 votes
public static FileInfo GetFileInfo(String filePath)
 {
File lFile = new File(filePath);
if (!lFile.exists())
  return null;

FileInfo lFileInfo = new FileInfo();
lFileInfo.canRead = lFile.canRead();
lFileInfo.canWrite = lFile.canWrite();
lFileInfo.isHidden = lFile.isHidden();
lFileInfo.fileName = Util.getNameFromFilepath(filePath);
lFileInfo.ModifiedDate = lFile.lastModified();
lFileInfo.IsDir = lFile.isDirectory();
lFileInfo.filePath = filePath;
lFileInfo.fileSize = lFile.length();
return lFileInfo;
 }
 
Example 2
Project: hadoop   File: JarFinder.java   View Source Code Vote up 6 votes
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();
        }
        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);
          copyToZipStream(f, anEntry, zos);
        }
      }
    }
  }
}
 
Example 3
Project: Reer   File: ExtensionFileFilter.java   View Source Code Vote up 5 votes
public boolean accept(File file) {
    if (file.isHidden()) {
        return false;
    }

    if (file.isDirectory()) {
        return true;
    }

    return file.getName().toLowerCase().endsWith(extension);
}
 
Example 4
Project: PackagePlugin   File: FileUtil.java   View Source Code Vote up 5 votes
/**
 * 递归查找单个文件,找到结果就返回
 *
 * @param rootDirPath 查找起始目录
 * @param paths       要查找的文件路径
 * @param depth       查找深度
 * @return
 */
public static File searchOneFile(String rootDirPath, String[] paths, int depth) {
    File rootDir = new File(rootDirPath);
    if (!rootDir.exists() || !rootDir.isDirectory()) {
        return null;
    }
    FileTree tree = FILE_TREE.searchByPath(paths);//优先通过缓存数据查找
    if (tree != null) {
        return new File(tree.getAbsolutePath());
    }
    File[] listFiles = rootDir.listFiles(new FileFilter() {

        @Override
        public boolean accept(File pathname) {
            return !pathname.isHidden();
        }
    });
    for (File listFile : listFiles) {
        if (!listFile.isHidden() && !listFile.getName().endsWith(".java") && !listFile.getName().startsWith(".")) {
            FILE_TREE.addChild(listFile);//扫描过的文件存储到多叉树中
        }
        if (!checkPath(paths, listFile)) {//路径不匹配时跳出当前路径遍历
            continue;
        }
        if (listFile.getName().equals(paths[paths.length - 1])) {
            File pFile = listFile.getParentFile();
            if (pFile.getName().equals(paths[paths.length - 2]) && pFile.getParentFile().getName().equals(paths[paths.length - 3])) {
                return listFile;
            }
        }
        if (listFile.isDirectory() && !listFile.getName().startsWith(".") && !listFile.isHidden() && depth > 0) {
            File file = searchOneFile(listFile.getAbsolutePath(), paths, depth--);
            if (file != null) {
                return file;
            }
        }
    }
    return null;
}
 
Example 5
Project: uavstack   File: UpgradeDownloadTask.java   View Source Code Vote up 5 votes
/**
 * Handle the request for downloading upgrade file
 * 
 * @param baseDir:
 *            the base directory
 * @param software:
 *            work as the sub directory for storing target zip file
 * @param target:
 *            the name of target zip file
 */
private void handleDownloadRequest(String baseDir, String software, String target) {

    Path path = Paths.get(baseDir, software, target);

    if (log.isTraceEnable()) {
        log.info(this, "Downloading " + target);
    }

    File file = path.toFile();

    if (!file.exists() || file.isHidden()) {
        sendRspStatus(NOT_FOUND);
        return;
    }

    if (file.isDirectory()) {
        sendListing(file);
        return;
    }

    if (!file.isFile()) {
        sendRspStatus(FORBIDDEN);
        return;
    }

    httpMsg.putResponseBodyInChunkedFile(file);
}
 
Example 6
Project: rapidminer   File: SimpleFolder.java   View Source Code Vote up 5 votes
private void ensureLoaded() throws RepositoryException {
	if (data != null && folders != null) {
		return;
	}
	data = new ArrayList<DataEntry>();
	folders = new ArrayList<Folder>();
	File fileFolder = getFile();
	if (fileFolder != null && fileFolder.exists()) {
		File[] listFiles = fileFolder.listFiles();
		for (File file : listFiles) {
			if (file.isHidden()) {
				continue;
			}
			if (file.isDirectory()) {
				folders.add(new SimpleFolder(file.getName(), this, getRepository()));
			} else if (file.getName().endsWith(".ioo")) {
				data.add(new SimpleIOObjectEntry(file.getName().substring(0, file.getName().length() - 4), this,
						getRepository()));
			} else if (file.getName().endsWith(".rmp")) {
				data.add(new SimpleProcessEntry(file.getName().substring(0, file.getName().length() - 4), this,
						getRepository()));

			} else if (file.getName().endsWith(".blob")) {
				data.add(new SimpleBlobEntry(file.getName().substring(0, file.getName().length() - 5), this,
						getRepository()));
			}
		}
		Collections.sort(data, NAME_COMPARATOR);
		Collections.sort(folders, NAME_COMPARATOR);
	}
}
 
Example 7
Project: Tedyli-Searcher   File: Indexer.java   View Source Code Vote up 5 votes
public int createIndex(String dataDirPath, FileFilter filter) throws IOException {
	File[] files = new File(dataDirPath).listFiles();
	for (File file : files) {
		if (!file.isDirectory() && !file.isHidden() && file.exists() && file.canRead() && filter.accept(file)) {
			indexFile(file);
		}
	}
	return writer.numDocs();
}
 
Example 8
Project: Equella   File: LocalBackend.java   View Source Code Vote up 5 votes
@Override
public List<FileInfo> listFiles(String directory)
{
	FileFilter filter = new FileFilter()
	{
		@Override
		public boolean accept(File pathname)
		{
			return !pathname.isHidden();
		}
	};

	List<FileInfo> results = new ArrayList<FileInfo>();
	for( File file : getActualFile(directory).listFiles(filter) )
	{
		FileInfo info = new FileInfo();
		info.setPath(directory);
		info.setName(file.getName());
		info.setDirectory(file.isDirectory());
		info.setSize(file.length());
		info.setLastModified(file.lastModified());
		info.setMarkAsAttachment(markedAsResources.contains(info.getFullPath()));

		results.add(info);
	}
	return results;
}
 
Example 9
Project: jijimaku   File: WorkerAnnotate.java   View Source Code Vote up 5 votes
/**
 * Process one file.
 * @return if the file was annotated, false otherwise.
 */
private boolean processFile(File fileEntry) throws IOException, FatalParsingException {
  String fileContents = FileManager.fileAnyEncodingToString(fileEntry);
  if (fileEntry.isHidden() || SubtitleFile.isJijimakuFile(fileContents)) {
    LOGGER.debug("{} is one of our annotated subtitle, skip it.", fileEntry.getName());
    return false;
  }
  String fileName = fileEntry.getName();
  String fileBaseName = FilenameUtils.getBaseName(fileName);

  LOGGER.info("Processing " + fileName + "...");
  String[] annotated = annotationService.annotateSubtitleFile(fileName, fileContents);
  if (annotated == null) {
    LOGGER.info("Nothing to annotate was found in this file(wrong language?)");
    return false;
  }

  // For ASS files, make a copy because the original file will be overwritten
  if (FilenameUtils.getExtension(fileName).equals("ass")) {
    if (fileBaseName.endsWith(ASS_FILE_BACKUP_SUFFIX)) {
      // This is already our copy, just remove suffix when writing out the result
      fileBaseName = fileBaseName.substring(0, fileBaseName.lastIndexOf(ASS_FILE_BACKUP_SUFFIX));
    } else {
      Files.copy(Paths.get(fileEntry.toURI()), Paths.get(fileEntry.getParent() + "/" + fileBaseName + ASS_FILE_BACKUP_SUFFIX + ".ass"));
    }
  }

  String outFile = fileEntry.getParent() + "/" + fileBaseName + ".ass";
  FileManager.writeStringArrayToFile(outFile, annotated);
  return true;
}
 
Example 10
Project: HFSN   File: Pages.java   View Source Code Vote up 5 votes
public static StringBuilder getDirectory(File dir) {
        String dirPath = dir.getPath();
        StringBuilder buf = new StringBuilder()
                .append("<!DOCTYPE html>\r\n")
                .append("<html><head><title>")
                .append("Listing of: ")
                .append(dirPath)
                .append("</title></head><body>\r\n")
                .append("<h3>\t Listing of: ")
                .append(dirPath)
                .append("</h3>\r\n")
                .append("<hr />\r\n")
                .append("<ul>\r\n")
                .append("<li><a href=\"../\">..</a></li>\r\n");
        //String fileCode = SystemPropertyUtil.get("file.encoding");
        for (File f : dir.listFiles()) {
            if (f.isHidden() || !f.canRead()) {
                continue;
            }
            //String name = new String(f.getName().getBytes(), fileCode);
            String name = f.getName();
//            if (!ALLOWED_FILE_NAME.matcher(name).matches()) {
//                continue;
//            }
            // System.out.println(name);
            buf.append("<li><a href=\"")
                    .append(name)
                    .append("\">")
                    .append(name)
                    .append("</a></li>\r\n");
        }
        buf.append("</ul>\r\n</body></html>\r\n");
        return buf;
    }
 
Example 11
Project: JRF   File: FileInfos.java   View Source Code Vote up 5 votes
public FileInfos(File f) {
	name = f.getName();
	if (name.isEmpty()) // Happens when 'f' is a root
		name = f.getPath();
	length = f.length();
	lastModified = f.lastModified();
	attributes = 0;
	if (f.isDirectory()) attributes |= BIT_ISDIRECTORY;
	if (f.isFile())      attributes |= BIT_ISFILE;
	if (f.isHidden())    attributes |= BIT_ISHIDDEN;
	if (f.canRead())     attributes |= BIT_CANREAD;
	if (f.canWrite())    attributes |= BIT_CANWRITE;
	if (f.canExecute())  attributes |= BIT_CANEXECUTE;
}
 
Example 12
Project: convertigo-engine   File: ListDirStep.java   View Source Code Vote up 5 votes
@Override
protected void createStepNodeValue(Document doc, Element stepNode) throws EngineException {
	try {
		// Command line string
		if (evaluated instanceof org.mozilla.javascript.Undefined)
			throw new EngineException("Source directory path is empty.");
		String path = Engine.theApp.filePropertyManager.getFilepathFromProperty(evaluated.toString(), getProject().getName());
		
        File fDir = new File(path);
        File[] files = fDir.listFiles();
        if (files == null)
        	throw new EngineException("Source path \""+path+"\" isn't a directory.");
        
        String fileName, fileLastModified, fileSize;
        Element element;
        File file;
        for (int i = 0 ; i < files.length ; i++) {
            file = files[i];
            if (file.isFile() && !file.isHidden()) {
            	fileName = file.getName();
            	fileSize = String.valueOf(file.length());
            	fileLastModified = String.valueOf(file.lastModified());
            	
            	element = doc.createElement("file");
            	element.appendChild(doc.createTextNode(fileName));
            	element.setAttribute("lastModified", fileLastModified);
            	element.setAttribute("size", fileSize);
            	stepNode.appendChild(element);
            }
        }
		
	}
	catch (Exception e) {
		setErrorStatus(true);
		Engine.logBeans.warn("An error occured while listing directory.", e);
	}
}
 
Example 13
Project: echo   File: GetFileFromAttribute.java   View Source Code Vote up 4 votes
private FileFilter createFileFilter(final ProcessContext context, String directory) {
    final long minSize = context.getProperty(MIN_SIZE).asDataSize(DataUnit.B).longValue();
    final Double maxSize = context.getProperty(MAX_SIZE).asDataSize(DataUnit.B);
    final long minAge = context.getProperty(MIN_AGE).asTimePeriod(TimeUnit.MILLISECONDS);
    final Long maxAge = context.getProperty(MAX_AGE).asTimePeriod(TimeUnit.MILLISECONDS);
    final boolean ignoreHidden = context.getProperty(IGNORE_HIDDEN_FILES).asBoolean();
    final Pattern filePattern = Pattern.compile(context.getProperty(FILE_FILTER).getValue());
    final String indir = directory;
    		//context.getProperty(DIRECTORY).evaluateAttributeExpressions().getValue();
    final boolean recurseDirs = context.getProperty(RECURSE).asBoolean();
    final String pathPatternStr = context.getProperty(PATH_FILTER).getValue();
    final Pattern pathPattern = (!recurseDirs || pathPatternStr == null) ? null : Pattern.compile(pathPatternStr);
    final boolean keepOriginal = context.getProperty(KEEP_SOURCE_FILE).asBoolean();

    return new FileFilter() {
        @Override
        public boolean accept(final File file) {
            if (minSize > file.length()) {
                return false;
            }
            if (maxSize != null && maxSize < file.length()) {
                return false;
            }
            final long fileAge = System.currentTimeMillis() - file.lastModified();
            if (minAge > fileAge) {
                return false;
            }
            if (maxAge != null && maxAge < fileAge) {
                return false;
            }
            if (ignoreHidden && file.isHidden()) {
                return false;
            }
            if (pathPattern != null) {
                Path reldir = Paths.get(indir).relativize(file.toPath()).getParent();
                if (reldir != null && !reldir.toString().isEmpty()) {
                    if (!pathPattern.matcher(reldir.toString()).matches()) {
                        return false;
                    }
                }
            }
            //Verify that we have at least read permissions on the file we're considering grabbing
            if (!Files.isReadable(file.toPath())) {
                return false;
            }

            //Verify that if we're not keeping original that we have write permissions on the directory the file is in
            if (keepOriginal == false && !Files.isWritable(file.toPath().getParent())) {
                return false;
            }
            return filePattern.matcher(file.getName()).matches();
        }
    };
}
 
Example 14
Project: netty_op   File: NettyHttpFileServerHandler.java   View Source Code Vote up 4 votes
/**
     *@description 返回目录结构数据
     *@time 创建时间:2017年9月15日下午2:44:41
     *@param ctx
     *@param dir
     *@author dzn
     */
    private static void sendListing(ChannelHandlerContext ctx, File dir){
        FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
//        response.headers().set("CONNECT_TYPE", "text/html;charset=UTF-8");
        response.headers().set(HttpHeaderNames.CONTENT_TYPE, "text/html;charset=UTF-8");
        
        String dirPath = dir.getPath();
        StringBuilder buf = new StringBuilder();
        
        buf.append("<!DOCTYPE html>\r\n");
        buf.append("<html><head><title>");
        buf.append(dirPath);
        buf.append("目录:");
        buf.append("</title></head><body>\r\n");
        
        buf.append("<h3>");
        buf.append(dirPath).append(" 目录:");
        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");
        
        ByteBuf buffer = Unpooled.copiedBuffer(buf,CharsetUtil.UTF_8);  
        response.content().writeBytes(buffer);  
        buffer.release();  
        ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE); 
    }
 
Example 15
Project: proxyee-down   File: HttpDownController.java   View Source Code Vote up 4 votes
@RequestMapping("/getChildDirList")
public ResultInfo getChildDirList(@RequestParam String model,
    @RequestBody(required = false) DirInfo body) {
  ResultInfo resultInfo = new ResultInfo();
  List<DirInfo> data = new LinkedList<>();
  resultInfo.setData(data);
  File[] files;
  if (body == null || StringUtils.isEmpty(body.getPath())) {
    files = File.listRoots();
  } else {
    File file = new File(body.getPath());
    if (file.exists() && file.isDirectory()) {
      files = file.listFiles();
    } else {
      resultInfo.setStatus(ResultStatus.BAD.getCode()).setMsg("路径不存在");
      return resultInfo;
    }
  }
  if (files != null && files.length > 0) {
    boolean isFileList = "file".equals(model);
    for (File tempFile : files) {
      if (tempFile.isFile()) {
        if (isFileList) {
          data.add(new DirInfo(
              StringUtils.isEmpty(tempFile.getName()) ? tempFile.getAbsolutePath()
                  : tempFile.getName(), tempFile.getAbsolutePath(), true));
        }
      } else if (tempFile.isDirectory() && (tempFile.getParent() == null || !tempFile
          .isHidden())) {
        DirInfo dirInfo = new DirInfo(
            StringUtils.isEmpty(tempFile.getName()) ? tempFile.getAbsolutePath()
                : tempFile.getName(), tempFile.getAbsolutePath(),
            tempFile.listFiles() == null ? true : Arrays.stream(tempFile.listFiles())
                .noneMatch(file ->
                    file != null && (file.isDirectory() || isFileList) && !file.isHidden()
                ));
        data.add(dirInfo);
      }
    }
  }
  return resultInfo;
}
 
Example 16
Project: ProjectAres   File: FileUtils.java   View Source Code Vote up 4 votes
public static boolean isHidden(File file) {
    return file.isHidden() || file.getName().startsWith(".");
}
 
Example 17
Project: fort_j   File: ClassesIt.java   View Source Code Vote up 4 votes
/**
 * Finds all classes in the java.class.path
 */
public ClassesIt()
{
   ignoredDirs.add(file("."));
   ignoredDirs.add(file(System.getProperty("user.home")));
   ignoredDirs.add(file("/"));

   //File workingDir = file(".");
   List<String> paths = Classes.getClassPath();

   Set<String> jarNames = new HashSet();

   for (String path : paths)
   {
      path = path.trim();
      if (path.length() == 0)
         continue;

      try
      {
         File f = file(path);
         if (f.exists() && !f.isHidden() && !stack.contains(f))
         {
            String name = f.getName();
            if (f.isFile() && name.endsWith(".jar") || name.endsWith(".zip"))
            {
               if (!jarNames.contains(name))
               {
                  jarNames.add(name);
                  stack.add(new Dir(null, f));
               }
            }
            else if (!f.isFile() && !ignoredDirs.contains(f))
            {
               //don't add an iterator for the working directory becuase it will most
               //likely not be useful and may contain zillions of directories
               stack.add(new Dir(f, f));
            }
         }
      }
      catch (Exception ex)
      {
         System.err.println(ex);
      }
   }
}
 
Example 18
Project: JavaGraph   File: ExtensionFilter.java   View Source Code Vote up 4 votes
/**
 * Accepts a file if its name ends on this filter's extension, or it is a
 * non-hidden directory with a (non-empty) pure name.
 * @see FileType#hasExtension(File)
 */
@Override
public boolean accept(File file) {
    return getFileType().hasExtension(file)
        || file.isDirectory() && !file.isHidden() && FileType.hasPureName(file);
}
 
Example 19
Project: lams   File: HiddenFileFilter.java   View Source Code Vote up 2 votes
/**
 * Checks to see if the file is hidden.
 * 
 * @param file  the File to check
 * @return {@code true} if the file is
 *  <i>hidden</i>, otherwise {@code false}.
 */
@Override
public boolean accept(File file) {
    return file.isHidden();
}
 
Example 20
Project: openjdk-jdk10   File: FileSystemView.java   View Source Code Vote up 2 votes
/**
 * Returns whether a file is hidden or not.
 *
 * @param f a {@code File} object
 * @return true if the given {@code File} denotes a hidden file
 */
public boolean isHiddenFile(File f) {
    return f.isHidden();
}