Note that there are some explanatory texts on larger screens.

plurals
  1. POJava - Get metadata of files in a directory with million files in it
    primarykey
    data
    text
    <p>I am writing a Java app to get the file metadata of files in a directory and exporting it to a csv file. The app works fine if the number of files is less. But if I feed in a path that has like a 320000 files in all of directories and sub-direcories it is taking forever. Is there a way I can speed up things here ? </p> <pre><code> private void extractDetailsCSV(File libSourcePath, String extractFile) throws ScraperException { log.info("Inside extract details csv"); try{ FileMetadataUtil fileUtil = new FileMetadataUtil(); File[] listOfFiles = libSourcePath.listFiles(); for(int i = 0; i &lt; listOfFiles.length; i++) { if(listOfFiles[i].isDirectory()) { extractDetailsCSV(listOfFiles[i],extractFile); } if(listOfFiles[i].isFile()){ ScraperOutputVO so = new ScraperOutputVO(); Path path = Paths.get(listOfFiles[i].getAbsolutePath()); so.setFilePath(listOfFiles[i].getParent()); so.setFileName(listOfFiles[i].getName()); so.setFileType(getFileType(listOfFiles[i].getAbsolutePath())); BasicFileAttributes basicAttribs = fileUtil.getBasicFileAttributes(path); if(basicAttribs != null) { so.setDateCreated(basicAttribs.creationTime().toString().substring(0, 10) + " " + basicAttribs.creationTime().toString().substring(11, 16)); so.setDateLastModified(basicAttribs.lastModifiedTime().toString().substring(0, 10) + " " + basicAttribs.lastModifiedTime().toString().substring(11, 16)); so.setDateLastAccessed(basicAttribs.lastAccessTime().toString().substring(0, 10) + " " + basicAttribs.lastAccessTime().toString().substring(11, 16)); } so.setFileSize(String.valueOf(listOfFiles[i].length())); so.setAuthors(fileUtil.getOwner(path)); so.setFolderLink(listOfFiles[i].getAbsolutePath()); writeCsvFileDtl(extractFile, so); so.setFileName(listOfFiles[i].getName()); noOfFiles ++; } } } catch (Exception e) { log.error("IOException while setting up columns" + e.fillInStackTrace()); throw new ScraperException("IOException while setting up columns" , e.fillInStackTrace()); } log.info("Done extracting details to csv file"); } public void writeCsvFileDtl(String extractFile, ScraperOutputVO scraperOutputVO) throws ScraperException { try { FileWriter writer = new FileWriter(extractFile, true); writer.append(scraperOutputVO.getFilePath()); writer.append(','); writer.append(scraperOutputVO.getFileName()); writer.append(','); writer.append(scraperOutputVO.getFileType()); writer.append(','); writer.append(scraperOutputVO.getDateCreated()); writer.append(','); writer.append(scraperOutputVO.getDateLastModified()); writer.append(','); writer.append(scraperOutputVO.getDateLastAccessed()); writer.append(','); writer.append(scraperOutputVO.getFileSize()); writer.append(','); writer.append(scraperOutputVO.getAuthors()); writer.append(','); writer.append(scraperOutputVO.getFolderLink()); writer.append('\n'); writer.flush(); writer.close(); } catch (IOException e) { log.info("IOException while writing to csv file" + e.fillInStackTrace()); throw new ScraperException("IOException while writing to csv file" , e.fillInStackTrace()); } } </code></pre> <p>}</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload