Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
I am still looking for the possibility in 2022 to use talend to check wether folders are empty or not .
The problem is that TfileProperties just focuses on files and not directories/folders
I want to find a way to determine the size of a folder whether it is empty or has something in it (files and non empty sub-directories ) which is simply to just check its SIZE if it is >0 or jsut 0 .
Is there any way to check folder/directory size ??
here is what i could achieve , i could read paths from a text file and loop through those paths and log each time if the size is 0 or not ;
the problem is that TFileProperties shows 0 when it does not find files directly under the path and shows more than 0 when it finds some files under that same path ; which is not true because sometimes the path has folders in it that are not empty ; in this case it should show more than 0 as size .
Hi
Just use a tFileList to iterate each file under the specified directory, if the side of one of the files >0, then we can say the directory is not empty, see below.
code on tJavaRow:
// code sample:
//
// multiply by 2 the row identifier
// output_row.id = input_row.id * 2;
//
// lowercase the name
// output_row.name = input_row.name.toLowerCase();
System.out.println(input_row.basename);
if(input_row.size>0){
context.isEmpty=false;
break;
}
Define a context variable with boolean type, set its default value as true;
Hope it helps!
Regards
Shong
Hello M.Shong .
Thank you for the reply .
I finished by using that same method of yours , i loop through files in a directory and do that same logic but the problem is i can't break the loop once i find a size >0 ; it always loops through all 4000 files under the folder even after i used an IF trigger that check if context.isEmpty false or not ! i don't understand why the loop does not break when the IF trigger is false .
Here is an image about the process i am trying to use to break the loop once i find a file that has size.
Please feel free to critisize my choice of triggers for optimisations , i think there can be a lot of optimisation in all those triggers and intermidiate components that i am using.
I don't understand why you use tFlowToIterate_4 component here, and I don't see where you break the loop, there are three iterations (loops) in your job, if you break the loop on tJava_6, i think only the innermost loop is terminated.
oh yeah what you are saying is true , the inner last loop is the only on that break because of the if .
i use iterate because i have no choice to use other triggers . is there a way on how i can optimize that please? is the singleiteration useless afterall ? can i delete it and keep the flow ?
also the tflowtoiterate is used to get the ROW2 values , is it mendatory i use tflowtoiterate to read the values from tFileProps?
Is it possible share me the job via email? It's hard for me to say how to optimize the job only with a screenshot, I don't know the purpose of each component you use.
i will send it later this day . which mail can i send it to ? shong@talend.com ?
yes, send the job to shong@talend.com