Skip to main content
Announcements
SYSTEM MAINTENANCE: Thurs., Sept. 19, 1 AM ET, Platform will be unavailable for approx. 60 minutes.
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

how to compare all list of file name in the same directory

Hi,

I have a need to compare the file name of the list of file and copy the last file in other directory

For exemple:

dir : nameDir

files: A1_scope_20180818.csv

        A1_scope_20180820.csv

        A2_scope_20180818.csv

        A3_scope_20180819.csv

        A4_scope_20180821.csv

        A4_scope_20180818.csv

So, i want to copy these files ( A1_scope_20180820.csv,A2_scope_20180818.csv, A3_scope_20180819.csv,A4_scope_20180821.csv

) in the other dirctory.

At the moment, i got the index, name and the date of each file. It means:

1, A1 , 20180818

2, A1, 20180820

3, A2, 20180818

4, A3, 20180819

5, A4,20180821

6, A4,20180818

 tFileList  --> tFixedFlowInput --> tMap -> tJavaRow --> tLogRow.

 

Now i want to comapre the name and date of one file with each other file to take the file of recent date.

 

any suggestions on how to do this?
thanks a lot,

ledoan

Labels (5)
8 Replies
TRF
Champion II
Champion II

Set a global variable in your tJavaRow to get the greater date:
if((Integer)globalMap.getOrDefault("maxDate", 0) < input_row.fileDate)
globalMap.put("maxDate", input_row.fileDate);

Now you can reuse this global variable from anywhere you want.
Anonymous
Not applicable
Author

Hello TRF,

i don't understand your reponse, can you explain more detailled please.

i want store these informations (index, name and date) of each file in the ArrayList and browse the list with its index to compare the file name.

 

i think to use ArrayList<HashMap<String, Date>> to store the values of variables name and date. But when i declare this ArrayList, it appears the errors (HashMap cannot be resolved  to type).

 

java.util.ArrayList<HashMap<String, Date>> test = new java.util.ArrayList<HashMap<String, Date>>();

 

Have you an idea for this.

Thanks 

Br

Giang

 

TRF
Champion II
Champion II

As you just need to get the max value for the date, you don't have to store all filenames to a list, a simple global variable is enough.
Then copy all the files to the same destination, and at the end move the file corresponding to the max date to the right place.
Anonymous
Not applicable
Author

Hello,

i need to store all filename and also the date of this filename because i want to remove duplicate files and keep only the files that have the newest date.

For ex: i have the list of file in the folder 1 (6 files)

         A1_scope_20180818.csv

        A1_scope_20180820.csv

        A2_scope_20180818.csv

        A3_scope_20180819.csv

        A4_scope_20180821.csv

        A4_scope_20180818.csv

After the traitement, i want to obtain the list of file in the folder 2 (4 files)

 A1_scope_20180820.csv, A2_scope_20180818.csv,  A3_scope_20180819.csv,  A4_scope_20180821.csv.

if i store only the max date in global variable, i can obtain only 1 file A4_scope_20180821.csv( file has the max date in its name file)

 

Giang

TRF
Champion II
Champion II

Just replace the hardcoded variable name (maxDate in my example) by the the name (input_row.name) and you'll have the max date for each name (A1, A2 and so on) instead of the max date for all the files.
TRF
Champion II
Champion II

Did this help?
If so, thank's to mark your case as solved (Kudo also accepted).
Anonymous
Not applicable
Author

Thanks so much for your help. 

Anonymous
Not applicable
Author

Hi can you please provide the zip file of your working job?