package lucee.runtime.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

import lucee.print;
import lucee.commons.io.IOUtil;

public class FileList {

	private static int count = 0;

	public static void list(File file) throws IOException {
		if (file.isFile()) {
			// (file.toString().endsWith(".cfm") || file.toString().endsWith(".cfc"))
			if ((file.toString().endsWith(".cfm") || file.toString().endsWith(".cfc") || file.toString().endsWith(".js") || file.toString().endsWith(".css"))
					&& file.toString().indexOf("/old_") == -1) {
				FileInputStream fis = new FileInputStream(file);
				try {
					String str = IOUtil.toString(fis, "UTF-8");
					//
					// if (str.indexOf("\"upload\"") != -1) print.e(file);
					// else if (str.indexOf("'upload'") != -1) print.e(file);
					// if (str.indexOf("filenameArray[filenameArray.length-1].toLowerCase() != 'jpg'") != -1)
					// print.e((++count) + " " + file);
					if (str.indexOf("newReleaseChangedArtwork") != -1) print.e((++count) + " " + file);
				}
				finally {
					IOUtil.closeEL(fis);
				}
			}
		}
		else if (file.isDirectory()) {
			File[] children = file.listFiles();
			if (children != null) for (File child: children) {
				list(child);
			}
		}
	}

	public static void main(String[] args) throws Exception {
		String path = "/Users/mic/Projects/Distrokid/distrokid";
		File f = new File(path);
		list(f);
	}
}

@@ -214,16 +214,627 @@
 t = 0;%0A%0A
+%09public static void listFileName(File file) throws IOException %7B%0A%09%09if (file.isFile()) %7B%0A%09%09%09// (file.toString().endsWith(%22.cfm%22) %7C%7C file.toString().endsWith(%22.cfc%22))%0A%09%09%09if ((file.toString().endsWith(%22.cfm%22) %7C%7C file.toString().endsWith(%22.cfc%22) %7C%7C file.toString().endsWith(%22.js%22) %7C%7C file.toString().endsWith(%22.css%22))%0A%09%09%09%09%09&& file.toString().indexOf(%22/old_%22) == -1) %7B%0A%09%09%09%09if (file.getName().toLowerCase().startsWith(%22application.cf%22)) print.e(file);%0A%09%09%09%7D%0A%09%09%7D%0A%09%09else if (file.isDirectory()) %7B%0A%09%09%09File%5B%5D children = file.listFiles();%0A%09%09%09if (children != null) for (File child: children) %7B%0A%09%09%09%09list(child);%0A%09%09%09%7D%0A%09%09%7D%0A%09%7D%0A%0A
 %09public 
@@ -874,32 +874,32 @@
 s IOException %7B%0A
-
 %09%09if (file.isFil
@@ -1561,24 +1561,27 @@
 file);%0A%09%09%09%09%09
+// 
 if (str.inde
@@ -1589,32 +1589,119 @@
 Of(%22
-newReleaseChangedArtwork
+emailDuplicateArtworkError%22) != -1) print.e((++count) + %22 %22 + file);%0A%09%09%09%09%09if (str.indexOf(%22Invalid image format
 %22) !

improve fileList