5 Replies - 311 Views - Last Post: 03 October 2013 - 11:47 AM Rate Topic: -----

#1 manojsharma3123  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 01-October 13

how to get multiple file Names from directory & write to csv

Posted 02 October 2013 - 08:44 AM


private static void FileNameToCSV(String sFileName){
    
FileNameToCSV("D:\\Users\\DIVYA\\Desktop\\TEST\\test1.csv");

try{        FileWriter writer = new FileWriter(sFileName);
            writer.append(sourcefilepath.getFilename());
	    writer.append('\n');
 
	    writer.flush();
	    writer.close();}
            
	catch(IOException e){
	     e.printStackTrace();}}


Is This A Good Question/Topic? 0
  • +

Replies To: how to get multiple file Names from directory & write to csv

#2 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2652
  • View blog
  • Posts: 11,191
  • Joined: 20-September 08

Re: how to get multiple file Names from directory & write to csv

Posted 02 October 2013 - 10:03 AM

Question unclear but check File.listFiles
Was This Post Helpful? 0
  • +
  • -

#3 manojsharma3123  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 01-October 13

Re: how to get multiple file Names from directory & write to csv

Posted 02 October 2013 - 01:22 PM

View Postg00se, on 02 October 2013 - 10:03 AM, said:

Question unclear but check File.listFiles





 private void listFiles(String directoryName) {
        File directory = new File(directoryName);
        File[] fList = directory.listFiles();
        for (File file : fList) {
            if (file.isFile()) {
                System.out.println(file.getName());//how to write these names in result.csv ??
            }
        }
 private void RunButtonActionPerformed(java.awt.event.ActionEvent evt) {                                          
        
       
        
        String sourceFilePath = SourceText.getText();
        String outputFilePath = OutputText.getText();

        if (sourceFilePath == null || sourceFilePath.equals("")) {
            JOptionPane.showMessageDialog(SourceText, "Select source folder path", "Alert", WIDTH);
        } else if (outputFilePath == null || outputFilePath.equals("")) {
            JOptionPane.showMessageDialog(OutputText, "Select output folder path", "Alert", WIDTH);
        }

        System.out.println("Source file  path " + sourceFilePath);
        System.out.println("Output file  path " + outputFilePath);

        FileNameToCSV listFilesUtil = new FileNameToCSV();
        final String directoryWindows = sourceFilePath;
        listFilesUtil.listFiles(sourceFilePath);
    }

Was This Post Helpful? 0
  • +
  • -

#4 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2652
  • View blog
  • Posts: 11,191
  • Joined: 20-September 08

Re: how to get multiple file Names from directory & write to csv

Posted 02 October 2013 - 01:31 PM

How many columns do you intend results.csv to have?
Was This Post Helpful? 0
  • +
  • -

#5 manojsharma3123  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 01-October 13

Re: how to get multiple file Names from directory & write to csv

Posted 03 October 2013 - 11:08 AM

Only One Column which is Column "A"
Was This Post Helpful? 0
  • +
  • -

#6 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2652
  • View blog
  • Posts: 11,191
  • Joined: 20-September 08

Re: how to get multiple file Names from directory & write to csv

Posted 03 October 2013 - 11:47 AM

So use a PrintWriter and println("A"), followed by every file path
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1