How to get the names of the files in a specific directory (folder) to a text file?
Today my mother asked me to write some MP3s into a DVD. There were nearly 200 MP3 files.
and she also asked me to number them and make a list of file names to print out.
I was like o.O how am I going to do that? type all 200 file names into a document? I felt lazy and thought why can't I write a program that will do it for me !. so I wrote a simple program that gets file names and writes them into a text file, so I can print them out. This is the simple program I wrote. It took less than 2 minutes to write it. and saved a considerable amount of time! ;)
I made a little GUI with the above code in case if I needed that later. If you like to try you can download this and try it your self :) I've included the source code, a jar file, and executable file of this GUI
Click here to Download Fnames2txt.zip
Today my mother asked me to write some MP3s into a DVD. There were nearly 200 MP3 files.
and she also asked me to number them and make a list of file names to print out.
I was like o.O how am I going to do that? type all 200 file names into a document? I felt lazy and thought why can't I write a program that will do it for me !. so I wrote a simple program that gets file names and writes them into a text file, so I can print them out. This is the simple program I wrote. It took less than 2 minutes to write it. and saved a considerable amount of time! ;)
1: import java.io.BufferedWriter;
2: import java.io.File;
3: import java.io.FileWriter;
4: import java.io.IOException;
5:
6: public class FilenamesToTxt {
7: public static void main(String[] args) throws IOException {
8: File folder = new File("C:/My Folder");
9: BufferedWriter bf = new BufferedWriter(new FileWriter(
10: "C:/filenames.txt"));
11:
12: for (File f : folder.listFiles()) {
13: bf.write(f.getName() + "\r\n");
14: }
15: bf.close();
16: }
17: }
I made a little GUI with the above code in case if I needed that later. If you like to try you can download this and try it your self :) I've included the source code, a jar file, and executable file of this GUI
Click here to Download Fnames2txt.zip
nice bro :)
ReplyDeletethanks bro!! :)
Delete