//Java code to list all files in a directory and sub-directories
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.attribute.BasicFileAttributes;
import com.csvreader.CsvWriter;
public class FilesFromDirectories {
static long fileSize;
static String size;
static CsvWriter csvOutput;
public static <lang> void main(String a[]) throws IOException{
//Folder path
File file = new File(" D://learn");
//Out put csv file
File file2 = new File("D:\\output.csv");
if ( !file2.exists() ){
file2.createNewFile();
}
csvOutput= new CsvWriter(new FileWriter(file2, true), ',');
csvOutput.write("File Name");
csvOutput.write("Creation Time");
csvOutput.write("Size");
csvOutput.write("Full Path");
csvOutput.endRecord();
listfiles(file.toString());
}
public static void listfiles(String directoryName) throws IOException {
File directory = new File(directoryName);
BasicFileAttributes attributes = null;
File[] fList = directory.listfilesiles();
try
{
for (File f : fList) {
if (f.isFile()) {
attributes = Files.readAttributes(f.toPath(), BasicFileAttributes.class);
//System.out.println("File Name ="+f.getName());
fileSize= f.length();
size=String.valueOf(fileSize);
//System.out.println("File Size :: " + fileSize);
// System.out.println("File Size :: " + f);
System.out.println("File Name :: "+ f.getName()+"Size :: "+ size + "Full Path "+f.toString());
System.out.println("Creation Time ::"+attributes.creationTime());
csvOutput.write(f.getName());
csvOutput.write(attributes.creationTime().toString());
csvOutput.write(size);
csvOutput.write(f.toString());
csvOutput.endRecord();
} else if (f.isDirectory()) {
System.out.println(f);
listfiles(f.getAbsolutePath());
}
csvOutput.flush();
}
}
catch(IOException exception)
{
System.out.println("Exception handled when trying to get file " +
"attributes: " + exception.getMessage());
}
}
}
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.attribute.BasicFileAttributes;
import com.csvreader.CsvWriter;
public class FilesFromDirectories {
static long fileSize;
static String size;
static CsvWriter csvOutput;
public static <lang> void main(String a[]) throws IOException{
//Folder path
File file = new File(" D://learn");
//Out put csv file
File file2 = new File("D:\\output.csv");
if ( !file2.exists() ){
file2.createNewFile();
}
csvOutput= new CsvWriter(new FileWriter(file2, true), ',');
csvOutput.write("File Name");
csvOutput.write("Creation Time");
csvOutput.write("Size");
csvOutput.write("Full Path");
csvOutput.endRecord();
listfiles(file.toString());
}
public static void listfiles(String directoryName) throws IOException {
File directory = new File(directoryName);
BasicFileAttributes attributes = null;
File[] fList = directory.listfilesiles();
try
{
for (File f : fList) {
if (f.isFile()) {
attributes = Files.readAttributes(f.toPath(), BasicFileAttributes.class);
//System.out.println("File Name ="+f.getName());
fileSize= f.length();
size=String.valueOf(fileSize);
//System.out.println("File Size :: " + fileSize);
// System.out.println("File Size :: " + f);
System.out.println("File Name :: "+ f.getName()+"Size :: "+ size + "Full Path "+f.toString());
System.out.println("Creation Time ::"+attributes.creationTime());
csvOutput.write(f.getName());
csvOutput.write(attributes.creationTime().toString());
csvOutput.write(size);
csvOutput.write(f.toString());
csvOutput.endRecord();
} else if (f.isDirectory()) {
System.out.println(f);
listfiles(f.getAbsolutePath());
}
csvOutput.flush();
}
}
catch(IOException exception)
{
System.out.println("Exception handled when trying to get file " +
"attributes: " + exception.getMessage());
}
}
}
Thanks for giving great kind of information. Very useful and practical for me. Thanks for your excellent blog, nice work keep it up thanks for sharing the knowledge.
ReplyDeleteapi development company
Thanks for the helpful content . If you are looking a API Development so visit xettle.net site for the best company to provide fintech software.
ReplyDeleteThis is such a well-crafted article. I like how clearly you presented each point without making it confusing. Your writing style is simple yet powerful. Looking forward to your next post.
ReplyDeletegmb seo services
This is a very informative post for Java learners who want to upgrade their skills with modern technologies. Combining Java development with AI concepts and real-time project experience is a great way to become industry-ready. Learners looking for practical exposure can explore AI Powered Java Real Time Projects Online Training in Hyderabad to understand how real-world applications are designed and implemented using current industry standards.
ReplyDeleteI am a happy person today having to have recovered a large amount of money worth 10,000, which I had lost in the hands of Bitcoin fraudulent, It has been an unfortunate year for me trying to recover my money back for the last 2months but luckily a friend of mine who also went through the same scamming issue referred me to this recovery agent called Boleyn Magic Hackers It took 3days for them to recovery the full amount at first I was hesitant and scared to believe them since I have also lost some money trying to recover my money back, But my friend assured me that they are very reliably and I decided to try it a try I have never been happy in my life until today, I would advise anyone out here trying to recover your money back you all should trust Boleyn Magic Hackers If you are a victim of bitcoin scam and believe in recovering all your lost funds, Their insights, and dedication showed me a path to success I never knew existed. This is the Email address you can use to reach out to them: Email:support@boleynonline.com. I am aware that sometimes Bitcoin cannot be recovered. However, I think it's critical to provide this choice to those who have misplaced their Bitcoin. We appreciate you offering this helpful service, Boleyn Magic Hackers (BMH). My life was spared by Boleyn Experts, which is why I am sharing this Bitcoin recovery success story in their honor. I am also appreciative of how popular Bitcoin recovery is becoming. This implies that more users will be able to use Boleyn Magic Hackers' online recovery through email:support@boleynonline.com to recover their lost Bitcoin because more people will be aware of the scam.
ReplyDelete