-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
55722f2
commit f6b22d8
Showing
3 changed files
with
204 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* file DirectoryStatistics.java | ||
* M. MAURICARD Francois-Xavier Pascal - 16/03/2006 | ||
*/ | ||
|
||
public class DirectoryStatistics extends Object | ||
{ | ||
// Attributes. | ||
public int file_count; | ||
public long directory_size; | ||
|
||
// Constructors. | ||
public DirectoryStatistics() | ||
{ | ||
this.file_count = 0; | ||
this.directory_size = 0; | ||
} | ||
|
||
// Instance methods. | ||
public void add(DirectoryStatistics ds) | ||
{ | ||
this.file_count += ds.file_count; | ||
this.directory_size += ds.directory_size; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
@java ListMP3 A:\ B:\ C:\ D:\ E:\ F:\ G:\ H:\ I:\ J:\ K:\ L:\ M:\ N:\ O:\ P:\ Q:\ R:\ S:\ T:\ U:\ V:\ W:\ X:\ Y:\ Z:\ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
/* | ||
* file ListMP3.java | ||
* M. MAURICARD Francois-Xavier Pascal - 16/03/2006 | ||
*/ | ||
|
||
import java.io.File; | ||
import java.io.FileWriter; | ||
import java.lang.String; | ||
|
||
class ListMP3 | ||
{ | ||
public static void main (String[] args) | ||
{ | ||
System.out.println("\nListMP3 v0.3_stable-20060316 by Francois-Xavier MAURICARD\n"); | ||
|
||
if (args.length == 0) | ||
{ | ||
System.out.println("Error : Too less arguments.\nUsage : java ListMP3 [directory] ..."); | ||
return; | ||
} | ||
|
||
// Deleting the potential existing output file. | ||
File output = new File("list.htm"); | ||
if (output.exists()) | ||
{ | ||
System.out.println("Deleting existing output file..."); | ||
output.delete(); | ||
} | ||
|
||
writeXHTMLHeader(output); | ||
writeLine(output, "\t\t<hr />\n"); | ||
|
||
DirectoryStatistics ds = new DirectoryStatistics(); | ||
for (String s : args) | ||
{ | ||
File directory = new File(s); | ||
boolean error = false; | ||
|
||
// Test if directories passed in arguments exists and can be readed. | ||
if (!directory.exists()) | ||
{ | ||
System.out.println("Error : " + s + " does not exists."); | ||
error = true; | ||
} | ||
else if (!directory.isDirectory()) | ||
{ | ||
System.out.println("Error : " + s + " is not a directory."); | ||
error = true; | ||
} | ||
else if (!directory.canRead()) | ||
{ | ||
System.out.println("Error : " + s + " cannot be readed."); | ||
error = true; | ||
} | ||
|
||
if (!error) | ||
{ | ||
System.out.println("Processing folder " + directory + "..."); | ||
writeLine(output, "\t\t<h1>" + directory + "</h1>\n\t\t<p>\n"); | ||
ds.add(processDirectory(directory, directory)); | ||
writeLine(output, "\t\t</p>\n\t\t<hr />\n"); | ||
} | ||
} | ||
System.out.println("\n" + ds.file_count + " MP3s found for a total size of " + ds.directory_size / 1048576 + " MB."); | ||
writeLine(output, "\t\t<h3>" + ds.file_count + " MP3s found for a total size of " + ds.directory_size / 1048576 + " MB.</h3>\n"); | ||
writeXHTMLFooter(output); | ||
} | ||
|
||
public static DirectoryStatistics processDirectory(File f, File parent) | ||
{ | ||
DirectoryStatistics res = new DirectoryStatistics(); | ||
|
||
if (f.isDirectory()) | ||
{ | ||
// List files of the current directory. | ||
File[] files = f.listFiles(); | ||
|
||
// Test if the list is not null. | ||
if (files != null && files.length != 0) | ||
{ | ||
DirectoryStatistics ds = new DirectoryStatistics(); | ||
boolean containsMP3 = false; | ||
|
||
// Search if the current directory contains a MP3. | ||
for(int i = 0 ; i < files.length && !containsMP3 ; i++) | ||
{ | ||
String filename = files[i].getName(); | ||
|
||
filename = filename.toLowerCase(); | ||
containsMP3 = filename.endsWith(".mp3"); | ||
} | ||
// If it contains a MP3, we process it. | ||
if (containsMP3) | ||
{ | ||
// Managing output file. | ||
File output = new File("list.htm"); | ||
|
||
for (File file : files) | ||
{ | ||
ds.add(processDirectory(file, parent)); | ||
} | ||
|
||
// Deletes if necessary the '\' at the beggining of the String defining the child path. | ||
int root = 1; | ||
if ((parent.toString().charAt(parent.toString().length() - 1) == '\\')) | ||
{ | ||
root = 0; | ||
} | ||
|
||
writeLine(output, "\t\t " + f.toString().substring(parent.toString().length() + root) + "<small> - (" + ds.file_count + " tracks sizing " + ds.directory_size / 1048576 + " MB)</small><br />\n"); | ||
res.add(ds); | ||
} | ||
// If it not contains a MP3, we treat it like a directory: recursion. | ||
else | ||
{ | ||
for (File file : files) | ||
{ | ||
res.add(processDirectory(file, parent)); | ||
} | ||
} | ||
} | ||
} | ||
|
||
if (f.isFile()) | ||
{ | ||
String filename = f.getName(); | ||
|
||
// Test if the file is a MP3 or not. | ||
filename = filename.toLowerCase(); | ||
if (filename.endsWith(".mp3")) | ||
{ | ||
res.file_count++; | ||
res.directory_size = f.length(); | ||
// writeLine(new File("list.htm"), "\t\t <small><small>" + f.getName() +"</center></small></small><br />\n"); | ||
} | ||
} | ||
|
||
return res; | ||
} | ||
|
||
public static void writeXHTMLHeader(File f) | ||
{ | ||
writeLine(f, "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"); | ||
writeLine(f, "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n"); | ||
writeLine(f, "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n"); | ||
writeLine(f, "\t<head>\n"); | ||
writeLine(f, "\t\t<title>HTML document generated by ListMP3</title>\n"); | ||
writeLine(f, "\t\t<style type=\"text/css\">\n"); | ||
writeLine(f, "\t\t\th1 { font: bold ; font-size: x-large ; font-family: \"Arial\", Helvetica, sans-serif ; color: black }\n"); | ||
writeLine(f, "\t\t\th3 { text-align: center ; font: normal ; font-size: normal ; font-family: \"Arial\", Helvetica, sans-serif ; color: black }\n"); | ||
writeLine(f, "\t\t\th6 { text-align: center ; font: bold ; font-size: xx-small ; font-family: \"Arial\", Helvetica, sans-serif ; color: maroon }\n"); | ||
writeLine(f, "\t\t\tp { font: normal ; font-size: normal ; font-family: \"Arial\", Helvetica, sans-serif ; line-height: 1.0em ; color: black }\n"); | ||
writeLine(f, "\t\t</style>\n"); | ||
writeLine(f, "\t</head>\n"); | ||
writeLine(f, "\t<body>\n"); | ||
} | ||
|
||
public static void writeLine(File f, String s) | ||
{ | ||
try | ||
{ | ||
FileWriter fw = new FileWriter(f, true); | ||
fw.write(s); | ||
fw.close(); | ||
} | ||
catch (java.io.IOException e) | ||
{ | ||
System.out.println("Error : Could not create/write output file."); | ||
} | ||
} | ||
|
||
public static void writeXHTMLFooter(File f) | ||
{ | ||
writeLine(f, "\t\t<h6>Generated by ListMP3 v0.3 created by Francois-Xavier MAURICARD</h6>\n"); | ||
writeLine(f, "\t</body>\n"); | ||
writeLine(f, "</html>\n"); | ||
} | ||
} |