Load all files in a directory

hi all! im new to java and i was wondering if u can help me out!
ive wrote a small application which analysises words in a text file, and what i need to do is load all the files in a directory, rather than one at a time like in the following code. I understand that a loop is needed but i really dont know where to start! please help!
thanks for your time
oh also, is there a way of the system printing the filename rather than "this text is.."?
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
public class eval {
private String[] words;
private int[] values;
private int num;
private HashMap <String, Integer> hashMap;
private arrays a;
private String[] negwords;
private int[] negvalues;
private HashMap hashMap2;
private int negnum;
public eval() {
initiatemap();
BufferedReader in = null;
try {
in = new BufferedReader (new FileReader ("text.txt")); //id like this to load all files in a directory
String str;
String s;
while ((str = in.readLine()) != null)
str = str.replaceAll("[\\p{Punct}&&[^?????????????????????]]", " ");
String[]temp = str.split(" ");
for (int i = 0; i < temp.length; i++) {
if (hashMap.containsKey(temp)) {
num++;
for (int i = 0; i < temp.length; i++) {
if (hashMap2.containsKey(temp[i])) {
negnum++;
if (num > 0 && negnum > 0 ){
double total = num + negnum;
double txt1 = round((num/total)*100, 2);
if (txt1 < 50)
System.out.println("This text is " + txt1 + "% positive and is therefore not a happy text.");
else if (txt1 >= 50 && txt1 <=65)
System.out.println("This text is " + txt1 + "% positive, but does contain " + (100 - txt1) + "% negative words, it is therefore probably not a happy text.");
else if (txt1 > 65)
System.out.println("This text is " + txt1 + "% positive, and is therefore a happy text.");
in.close();
catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
public static double round(double val, int places) {
long factor = (long)Math.pow(10,places);
// Shift the decimal the correct number of places
// to the right.
val = val * factor;
// Round to the nearest integer.
long tmp = Math.round(val);
// Shift the decimal the correct number of places
// back to the left.
return (double)tmp / factor;
public void initiatemap()
a = new arrays();
words = a.initiateWords();
negwords = a.initiateNegWords();
values = a.initiateValues();
negvalues = a.initiateNegValues();
hashMap = a.initiateMap();
hashMap2 = a.initiateNegMap();
for (int i = 0; i < words.length; i++) {
hashMap.put(words[i], values[i]);}
for (int j = 0; j < negwords.length; j++) {
hashMap2.put(negwords[j], negvalues[j]);}
public static void main(String[] args) {
eval eval = new eval();

hi again,
ok thanks for the help, ive have made the changes and i am now getting results.. however the results aren't correct!
if i load the texts in one at a time, i get entirely different results to what is being printed. any suggestions?
thanks again, i really really appreciate your help
Torre
private static void readMultipleFilesFromADirectory()
File directory = new File(multipleFilesDirectory);
// just to double check that this is a directory
if (directory.isDirectory())
File[] allFilesWithinThisDirectory = directory.listFiles();
BufferedReader in = null;
for (File file: allFilesWithinThisDirectory)
initiatemap();
try {
in = new BufferedReader (new FileReader (file));
String str;
String s;
while ((str = in.readLine()) != null)
str = str.replaceAll("[
p{Punct}&&--^&aacute;&acirc;&atilde;&auml;&eacute;&ecirc;&euml;&igrave;&iacute;&icirc;&iuml;&ograve;&oacute;&ocirc;&ouml;&ugrave;&uacute;&ucirc;&uuml;&ccedil;&egrave;]--", " ");
String[]temp = str.split(" ");
for (int i = 0; i < temp.length; i++) {
if (hashMap.containsKey(temp)) {
num++;
for (int i = 0; i < temp.length; i++) {
if (hashMap2.containsKey(temp[i])) {
negnum++;
if (num > 0 && negnum > 0 ){
double total = num + negnum;
double txt1 = round((num/total)*100, 2);
if (txt1 < 50)
System.out.println(file + " is " + txt1 + "% positive and is therefore not a happy text.");
else if (txt1 >= 50 && txt1 <=65)
System.out.println(file +" is " + txt1 + "% positive, but does contain " + (100 - txt1) + "% negative words, it is therefore probably not a happy text.");
else if (txt1 > 65)
System.out.println(file +" is " + txt1 + "% positive, and is therefore a happy text.");
in.close();
catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
results:
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv416_11136.txt is 60.65% positive, but does contain 39.35% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv417_13115.txt is 60.66% positive, but does contain 39.34% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv418_14774.txt is 60.68% positive, but does contain 39.32% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv419_13394.txt is 60.69% positive, but does contain 39.31% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv420_28795.txt is 60.66% positive, but does contain 39.34% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv421_9709.txt is 60.65% positive, but does contain 39.35% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv422_9381.txt is 60.69% positive, but does contain 39.31% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv423_11155.txt is 60.69% positive, but does contain 39.31% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv424_8831.txt is 60.67% positive, but does contain 39.33% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv425_8250.txt is 60.67% positive, but does contain 39.33% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv426_10421.txt is 60.69% positive, but does contain 39.31% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv427_10825.txt is 60.66% positive, but does contain 39.34% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv428_11347.txt is 60.68% positive, but does contain 39.32% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv429_7439.txt is 60.69% positive, but does contain 39.31% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv430_17351.txt is 60.68% positive, but does contain 39.32% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv431_7085.txt is 60.67% positive, but does contain 39.33% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv432_14224.txt is 60.67% positive, but does contain 39.33% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv433_10144.txt is 60.66% positive, but does contain 39.34% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv434_5793.txt is 60.63% positive, but does contain 39.37% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv435_23110.txt is 60.62% positive, but does contain 39.38% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv436_19179.txt is 60.68% positive, but does contain 39.32% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv437_22849.txt is 60.69% positive, but does contain 39.31% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv438_8043.txt is 60.65% positive, but does contain 39.35% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv439_15970.txt is 60.68% positive, but does contain 39.32% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv440_15243.txt is 60.66% positive, but does contain 39.34% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv441_13711.txt is 60.64% positive, but does contain 39.36% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv442_13846.txt is 60.61% positive, but does contain 39.39% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv443_21118.txt is 60.61% positive, but does contain 39.39% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv444_9974.txt is 60.6% positive, but does contain 39.4% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv445_25882.txt is 60.56% positive, but does contain 39.44% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv446_11353.txt is 60.54% positive, but does contain 39.46% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv447_27332.txt is 60.54% positive, but does contain 39.46% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv448_14695.txt is 60.56% positive, but does contain 39.44% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv449_8785.txt is 60.55% positive, but does contain 39.45% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv450_7890.txt is 60.54% positive, but does contain 39.46% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv451_10690.txt is 60.54% positive, but does contain 39.46% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv452_5088.txt is 60.53% positive, but does contain 39.47% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv453_10379.txt is 60.56% positive, but does contain 39.44% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv454_2053.txt is 60.55% positive, but does contain 39.45% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv455_29000.txt is 60.55% positive, but does contain 39.45% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv456_18985.txt is 60.57% positive, but does contain 39.43% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv457_18453.txt is 60.53% positive, but does contain 39.47% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv458_8604.txt is 60.53% positive, but does contain 39.47% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv459_20319.txt is 60.5% positive, but does contain 39.5% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv460_10842.txt is 60.54% positive, but does contain 39.46% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv461_19600.txt is 60.48% positive, but does contain 39.52% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv462_19350.txt is 60.47% positive, but does contain 39.53% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv463_10343.txt is 60.49% positive, but does contain 39.51% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv464_15650.txt is 60.48% positive, but does contain 39.52% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv465_22431.txt is 60.46% positive, but does contain 39.54% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv466_18722.txt is 60.46% positive, but does contain 39.54% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv467_25773.txt is 60.45% positive, but does contain 39.55% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv468_15228.txt is 60.47% positive, but does contain 39.53% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv469_20630.txt is 60.42% positive, but does contain 39.58% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv470_15952.txt is 60.39% positive, but does contain 39.61% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv471_16858.txt is 60.4% positive, but does contain 39.6% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv472_29280.txt is 60.4% positive, but does contain 39.6% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv473_7367.txt is 60.38% positive, but does contain 39.62% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv474_10209.txt is 60.38% positive, but does contain 39.62% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv475_21692.txt is 60.42% positive, but does contain 39.58% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv476_16856.txt is 60.43% positive, but does contain 39.57% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv477_22479.txt is 60.48% positive, but does contain 39.52% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv478_14309.txt is 60.47% positive, but does contain 39.53% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv479_5649.txt is 60.44% positive, but does contain 39.56% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv480_19817.txt is 60.45% positive, but does contain 39.55% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv481_7436.txt is 60.43% positive, but does contain 39.57% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv482_10580.txt is 60.43% positive, but does contain 39.57% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv483_16378.txt is 60.44% positive, but does contain 39.56% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv484_25054.txt is 60.43% positive, but does contain 39.57% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv485_26649.txt is 60.45% positive, but does contain 39.55% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv486_9799.txt is 60.44% positive, but does contain 39.56% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv487_10446.txt is 60.42% positive, but does contain 39.58% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv488_19856.txt is 60.41% positive, but does contain 39.59% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv489_17906.txt is 60.4% positive, but does contain 39.6% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv490_17872.txt is 60.42% positive, but does contain 39.58% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv491_12145.txt is 60.44% positive, but does contain 39.56% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv492_18271.txt is 60.44% positive, but does contain 39.56% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv493_12839.txt is 60.43% positive, but does contain 39.57% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv494_17389.txt is 60.43% positive, but does contain 39.57% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv495_14518.txt is 60.41% positive, but does contain 39.59% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv496_10530.txt is 60.39% positive, but does contain 39.61% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv497_26980.txt is 60.39% positive, but does contain 39.61% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv498_8832.txt is 60.38% positive, but does contain 39.62% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv499_10658.txt is 60.38% positive, but does contain 39.62% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv500_10251.txt is 60.37% positive, but does contain 39.63% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv501_11657.txt is 60.34% positive, but does contain 39.66% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv502_10406.txt is 60.33% positive, but does contain 39.67% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv503_10558.txt is 60.35% positive, but does contain 39.65% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv504_29243.txt is 60.35% positive, but does contain 39.65% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv505_12090.txt is 60.3% positive, but does contain 39.7% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv506_15956.txt is 60.32% positive, but does contain 39.68% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv507_9220.txt is 60.3% positive, but does contain 39.7% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv508_16006.txt is 60.31% positive, but does contain 39.69% negative words, it is therefore probably not a happy text.
C:\Users\Torre\Desktop\panglee\txt_sentoken\pos\cv509_15888.txt is 60.39% positive, but does contain 39.61% negative words, it is therefore probably not a happy text.
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      

Similar Messages

  • How can I create a array with all files from a directory

    How can I create a array of files or varchar with all files from a directory?

    I thought the example could be improved upon. I've posted a solution on my blog that doesn't require writing the directory list to a table. It simply returns it as a nested table of files as a SQL datatype. You can find it here:
    http://maclochlainn.wordpress.com/2008/06/05/how-you-can-read-an-external-directory-list-from-sql/

  • How to get the file size (in bytes) for all files in a directory?

    How to get the file size (in bytes) for all files in a directory?
    The following code does not work. isFile() does NOT recognize files as files but only as directories. Why?
    Furthermore the size is not retrieved correctly.
    How do I have to code it otherwise? Is there a way of not converting f-to-string-to-File again but iterate over all file objects instead?
    Thank you
    Peter
    java.io.File f = new java.io.File("D:/todo/");
    files = f.list();
    for (int i = 0; i < files.length; i++) {
    System.out.println("fn=" + files);
    if (new File(files[i]).isFile())
         System.out.println("file[" + i + "]=" + files[i] + " size=" + (new File(files[i])).length() ); }

    pstein wrote:
    ...The following code does not work. Work?! It does not even compile! Please consider posting code in the form of an SSCCE in future.
    Here is an SSCCE.
    import java.io.File;
    class ListFiles {
        public static void main(String[] args) {
            java.io.File f = new java.io.File("/media/disk");
            // provides only the file names, not the path/name!
            //String[] files = f.list();
            File[] files = f.listFiles();
            for (int i = 0; i < files.length; i++) {
                System.out.println("fn=" + files);
    if (files[i].isFile()) {
    System.out.println(
    "file[" +
    i +
    "]=" +
    files[i] +
    " size=" +
    (files[i]).length() );
    }Edit 1:
    Also, in future, when posting code, code snippets, HTML/XML or input/output, please use the code tags to retain the indentation and formatting.   To do that, select the code and click the CODE button seen on the Plain Text tab of the message posting form.  It took me longer to clean up that code and turn it into an SSCCE, than it took to +solve the problem.+
    Edited by: AndrewThompson64 on Jul 21, 2009 8:47 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • List all files in a directory on a server that hosts the applet

    Hei :)
    I have a problem. I want to list all files in a directory on my server. ( http://www.foo.bar/tw )
    The applet is in the root folder ( http://www.foo.bar ).
    So i tried it like this
    File fi = new URL(getCodeBase() + "/all/").getFile();But when I try to list the files, I get a SecurityException.
    Can anyone help me out?
    Peace!
    LoCal

    http://search.java.sun.com/search/java/index.jsp?col=javaforums&qp=&qt=%2Blist+%2Bfile+%2Bserver

  • Finder not displaying all files in remote directory

    Sorry, this is a repost as I have gotten no response from my original request here: Finder not displaying all files in remote directory
    I've exported pictures from iPhoto on my iMac to a shared directory on my mac mini. When I access that directory from my iMac, I can see some but not all of the pictures. I know the pictures exported properly because I can see them all from the mac mini. I can open up a terminal window on my iMac and see all of the files; I can also open those files from the terminal.
    I'm running OSX 10.9.4 on both computers, with the mac mini also running OSX Server. I've placed a screen grab below from my iMac of what Finder sees vs what I can see from the terminal.
    Why isn't Finder displaying all of my files?

    thanks for responding
    Adding a new file to the shared folder results in me being able to see the new file from my clients regardless of where it was added from, however the "hidden" files do not suddenly pop up.
    I tried a few more experiments that had interesting results, but still didn't lead me to an answer.
    First I tried copying the files from the remote directory to a local directory; I did this in 2 different ways and had different results. Method A) I copied files from the mounted share to a local dir: "cp /Volumes/MyShare/dir/*.JPG .". Method B) I copied the files using secure copy: "scp user@server:/path/to/dir/*.JPG .".
    Method A resulted in Finder not being able to see the files in the local directory, while Method B did. This was interesting and lead me to suspect an issue with the way I am sharing the directory on the server. From Server settings I have both afp and smb checked. I tried enabling only one or the other and reconnecting; but this did not fix the problem.
    Next I tried exporting the photos from iPhoto again. Exporting them locally results in files that Finder can see. Exporting them to my server results the same bad behavior
    Getting desperate, I also tried renaming all of the files from "*.JPG" to "*.jpg" but this didn't help.
    One last experiment, I see the same behavior from both another Mac and a PC on my local network... FTP works fine.
    Any more ideas?

  • Is there any way to play all files in a directory by one url?

    Hi all,
    I am testing fms this days, I have put all my files(such as 1.mp3,2.mp3...n.mp3) in my directory.
    I can play single file fine with url like this:
    rtmp://localhost/mp3/mp3:x/2
    but i want to know is there any way to play all files in my direcotry?
    for example, user click the play button, the player(smp) automatic plays all files in the directory, link windows media server.
    Should I use playlist? Or there is another better way?
    Thanks a lot.

    Hi,
    FMS do not directly take a directory to play files, the file names have to be fetched some way (through script if needed) to make a playlist and then the play command needs to be repeated as many times.
    Thank you !

  • How to remove all files in a directory in java?

    I have tried method delete() of File ,
    but no effect!
    can anyone help me!
    thank you

    So, you have a directory and you want to delete all files in the directory. Here is some (untested) code:
    File dir = new File("C:\\tempdir");
    File[] files = dir.listFiles();
    for (int i = 0; i < files.length; ++i) {
      if (files.isFile()) {
    files[i].delete();
    Jesper

  • Creating an action that treats all files in a directory

    How can I make an action which changes the picture size and resolution for all files in a directory and saves the new versions of the files in a subdirectory?
    Thanks

    Macro Details wrote:
    First create your Sub directory. Then start the Action. Open file, Resisize save as (to Sub directory) then close the file.
    Now: File- Automate-Batch. Select your action and your folders and overide the open Command and the Save As Command.
    Frankly Norbert I think the Image processor way is easier but to each his own as they say.  

  • Deleting all files in a directory

    Hi,
    Is it possible to use cffile to delete all files in a
    directory. I have a function that creates a file in seperate parts
    and places the finished file into a folder. But I need a check to
    delete all files currently existing in said folder. I understand it
    is possible to query a folder for existing files and then use that
    query with cffile to delete the files... I just don't know how to
    do it.
    Thanks for your help

    I am not postivie, but I think I recall learning that the
    delete all function is prohibited via CF. You can delete specific
    files, though.
    If this is, in fact, the case, you could query the directory,
    and then loop through the resultant query, deleting each file one
    at a time.

  • [Bash] Massively replace text in all files of a directory

    Hi everybody,
    I wrote this small recursive function in order to massively replace some strings contained in all files of a directory (and all subdirectories). Any suggestions?
    replaceText() {
    # set the temporary location
    local tFile="/tmp/out.tmp.$$"
    # call variables
    local script="$2"
    local opts="${@:3}"
    browse() {
    for iFile in "$1"/*; do
    if [ -d "$iFile" ];then
    # enter subdirectory...
    browse "$iFile"
    elif [ -f $iFile -a -r $iFile ]; then
    echo "$iFile"
    sed $opts "s/$(echo $script)/g" "$iFile" > $tFile && mv $tFile "$iFile"
    else
    echo "Skip $iFile"
    fi
    done
    browse $1
    Syntax:
    replaceText [path] [script] [sed options (optional)]
    For example (it will replace "hello" with "hi" in all files):
    replaceText /home/user/mydir hello/hi
    Note: It is case-sensitive.
    Bye,
    grufo
    Last edited by grufo (2012-11-10 15:05:43)

    falconindy wrote:
    Yes, find is recursive and extremely good at its job.
    http://mywiki.wooledge.org/UsingFind
    Well
    falconindy wrote:Your lack of quoting is dangerous, as is your code injection in sed. I'm not sure why you're echoing a var inside a command substitution inside a sed expression, but it's going to be subject to word splitting, all forms of expansion, and may very well break the sed expression entirely, leading to bad things. A contrived example, but passing something like 'foo//;d;s/bar/' should effectively delete the contents of every file the function touches.
    So, if you consider it dangerous, you can adopt the whole "sed syntax" and confirm before continue...:
    replaceText() {
    # set the temporary location
    local tFile="/tmp/out.tmp.$$"
    # call variables
    local sedArgs="${@:2}"
    browse() {
    for iFile in "$1"/*; do
    if [ -d "$iFile" ];then
    # enter subdirectory...
    browse "$iFile"
    elif [ -f $iFile -a -r $iFile ]; then
    echo "$iFile"
    sed $sedArgs "$iFile" > $tFile && mv $tFile "$iFile"
    else
    echo "Skip $iFile"
    fi
    done
    while true; do
    read -p "Do you want to apply \"sed $sedArgs\" to all files contained in the directory $1? [y/n] " yn
    case $yn in
    [Yy]* ) browse $1; break;;
    * ) exit;;
    esac
    done
    Syntax:
    replaceText [parent directory] [sed arguments]
    Example:
    replaceText /your/path -r 's/OldText/NewText/g'
    or, if you want to work directly with the current directory...
    replaceText() {
    # set the temporary location
    local tFile="/tmp/out.tmp.$$"
    # call variables
    local sedArgs="$@"
    browse() {
    for iFile in "$1"/*; do
    if [ -d "$iFile" ];then
    # enter subdirectory...
    browse "$iFile"
    elif [ -f $iFile -a -r $iFile ]; then
    echo "$iFile"
    sed $sedArgs "$iFile" > $tFile && mv $tFile "$iFile"
    else
    echo "Skip $iFile"
    fi
    done
    while true; do
    read -p "Do you want to apply \"sed $sedArgs\" to all files contained in the directory $PWD? [y/n] " yn
    case $yn in
    [Yy]* ) browse $PWD; break;;
    * ) exit;;
    esac
    done
    Syntax:
    replaceText [sed arguments]
    Example:
    replaceText -r 's/OldText/NewText/g'
    What about?
    falconindy wrote:I'll also point out that declaring a function within a function doesn't provide any amount of scoping -- 'browse' will be declared in the user's namespace after running this function for the first time.
    See:
    function1() {
    function2() {
    echo "Ciao"
    function2
    function2 # error
    function1 # works

  • Load all file names in a directory to a SQL Table

    I need to load all the file names in a directory to a SQL table. It must be done via TSQL or SSIS. If using TSQL cannot use xp_cmdshell or any undocumented sprocs. So I am guessing it will be SSIS. But still open to suggestions. I am an SSIS newbie and need
    a nudge in the right direction of how to get the file names into a SQL table.
    Thanks

    Let me add a bit of background. We are sent a group of files. Each file has the ccyymmdd date attached to the name. Possible that we miss processing one day and the next day there are two sets of files in the directory. file1_20140101, file2_20140101,
    file1_20140102, file2_20140102. I cannot guarantee what the file names will be. Just know that i need to process the 20140101 files in one batch, and then the 20140102 files in the next batch. So thinking that i could read all the file names into a SQL table,
    distinct on the date and then sort by the date and pull off those files to process first. Thinking this will be done in SSIS. Open to any ideas or suggestions.

  • JFileChooser - Select All Files in the Directory

    Hi all. I am currently using JFileChooser and I need a functionality that will let the user choose a directory and then automatically select all the files that exists in that directory. I have tried looking around for references, but no luck so far. I hope someone can help. Thanks in advance.

    This is what I use frequently in my applications :
    * Requests the loading of all Images
    * in a directory.
    private void loadImageDirectory() {
      //create a FileFilter so the user only sees directories     
      javax.swing.filechooser.FileFilter dirfilter=new javax.swing.filechooser.FileFilter() {
        public boolean accept(File f) {
          if(f==null)
            return false;
          if(!f.isDirectory())
            return false;
          return true;
        public String getDescription() {
          return "Directories only";
      //now create the filechooser     
      JFileChooser jfc=new JFileChooser();
      jfc.setDialogTitle("Select a directory");
      jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
      //remove the standard FileFilters (otherwise shows files too     
      jfc.resetChoosableFileFilters();
      //Set a FileFilter for directories only
      jfc.addChoosableFileFilter(dirfilter);
      int result=jfc.showOpenDialog(this);
      jfc_image_dir=jfc.getCurrentDirectory();
      if(result==JFileChooser.APPROVE_OPTION) {
        //here i call a method that does something with the directory     
        iv.addDirectory(jfc.getSelectedFile());
    }This always worked for me ??
    You might want to try??

  • How to get all files in one directory

    Hi there,
    is there any way to get all the files in one directory?
    e.g. a method
    File[] getAllFiles(String directory){
    Thank you

    Just out of interest, which part of the File API was confusing?
    http://java.sun.com/j2se/1.5.0/docs/api/index.html
    If you look down the left-hand side, you'll see a frame listing "All File". If you select "File" from that list, it opens up the API in the right-hand frame. Quite near the top you'll find "listFiles".
    I only ask as this (and other questions easily answered by looking at the API) are frequently asked. Did you overlook it when you read the API or did you just not read it?
    I really want to know. I think there is scope to cater for that behaviour within this site. A nice API finder would be good; something more intelligent than the search function (which people use less frequently even than the API docs).

  • How do U to get the names of all files in a directory?

    Is there a simple way to get all names of the files in a directory and put them in an array of Strings? Sounds simple, but I don't have a clue how to do this. Thanks.

    Hi Kindoo,
    Create a instance of File object using the path of the Directory
    File fileDir = new File(directoryPath);
    To get the List of all the files in the directory use
    String[] strFiles = fileDir.list();
    This will solve your problem,
    Cheers
    Nagaraj

  • Transfer of all files in a directory tree using FTP adapter?

    Hi,
    I'm looking for a solution to transfer a whole directory tree, including the content, from one location to another using the FTP adapter.
    Is there an easy way to accomplish this?
    Any help would be appreciated.
    Thanks
    Sigrid

    Hi Sigrid,
    I'm just wondering on the need to do that using SOA. Is it a regular transfer or one time?
    There's a way to move a single file from one FTP location to another on the same or different FTP server (link to the cases). But in order to move all the files in a directory, you'll have to loop this. The high level steps will be:
    - List all the files recursively that are present in your directory using File List operation
    - Implement the MOVE file operation (or COPY operation) of the FTP Adapter
    - Invoke this MOVE operation in a while loop and pass the file names, as gathered from the File List operation, one by one to MOVE operation
    You can also use single Java Embedding activity and call a Java class that does the File Transfer but depends on your requirements.
    Let us know how you get along.
    Regards,
    Neeraj Sehgal

Maybe you are looking for

  • Why does safari not work on my MacBook pro when I close it and forget to quit safari?

    So I'll close my MacBook with safari "X"ed out but not quit. When I open my MacBook up about an hour or so later, I'll click on safari mad it doesn't load... It's not that big of a deal, it's just annoying to have to restart my computer every time I

  • How do I open multiple 'windows' in Entourage?

    I am using MS Entourage and would like to be able to open multiple windows within that program. For example, I would like to have both my calendar and address book opened at the same time in different windows. I have looked all over for a way to do t

  • Installing Oracle8i Personal Edition, Version 8.1.5 on Windows XP Pro

    I am trying to install Oracle8i Personal Edition, Version 8.1.5 on my system with Windows XP Pro on it. After copying the CD content to the Hard Drive and renaming symcjit.dll to symcjit_back.dll, and running the setup from the oracle folder on the C

  • Can't see video on Gallery Web

    Have a iDisk for many years, can see streaming vidéo on my original web site but when i put the same video on my galerie web iphoto can see all there, i create a new album for my video on galerie web can't see it ? http://gallery.mac.com/escapademedi

  • Error code 50 installing Adobe creative cloud

    I cannot get rid of this error message when trying to install adobe creative cloud desktop.  I was able to remove the old installation using the cleaner too, but cannot get a new installation to install.