Get last modified date of a file and perform action
Hi,
I am newbee and trying to understand how this Long time format of the tfileproperties "mtime" and sting format of mtime_string can be compared with current time. I gone through the forum but nothing help me. This date comparison is taking hell lot of time.
My Requirement
I need to check the last modified date of the file and if it is equal to current date then copy this file and transform to XML file form.
Here i have done the "copy the file"" and "transform to XML file actions"
But Only thing i need to do is verify the file last modified time and if it is equal to current date then perform the action.
Any help is really appreciates since i have been trying this for 2 days still the conversion is giving me lot of trouble.
I tried to use the mtime and mtime_string of tfileproperties and nothing is helping me. There should be simple way but not able to get it.
Attached the jobdesign
The mtime_string throwing the below error.
Starting job Testing1 at 22:06 12/05/2015.
connecting to socket on port 3999
connected
java.lang.NumberFormatException: For input string: "Tue "
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at routines.system.FastDateParser$DateParser.parse(FastDateParser.java:127)
at java.text.DateFormat.parse(Unknown Source)
at routines.TalendDate.parseDate(TalendDate.java:850)
at routines.TalendDate.parseDate(TalendDate.java:808)
at etl.testing1_0_1.Testing1.tFileProperties_1Process(Testing1.java:994)
at etl.testing1_0_1.Testing1.runJobInTOS(Testing1.java:1401)
at etl.testing1_0_1.Testing1.main(Testing1.java:1258)
Exception in component tMap_1
java.lang.RuntimeException: java.text.ParseException: Unparseable date: "Tue May 12 16:51:20 MDT 2015"
at routines.TalendDate.parseDate(TalendDate.java:864)
at routines.TalendDate.parseDate(TalendDate.java:808)
at etl.testing1_0_1.Testing1.tFileProperties_1Process(Testing1.java:994)
at etl.testing1_0_1.Testing1.runJobInTOS(Testing1.java:1401)
at etl.testing1_0_1.Testing1.main(Testing1.java:1258)
disconnected
Caused by: java.text.ParseException: Unparseable date: "Tue May 12 16:51:20 MDT 2015"
at java.text.DateFormat.parse(Unknown Source)
at routines.TalendDate.parseDate(TalendDate.java:850)
... 4 more
Job Testing1 ended at 22:06 12/05/2015.
The Jobdesign
tfileProperties-->tfilterColumn-->tmap--LogRow
the tMap
row2 modified_output
mtime_string --> TalendDate.parseDate("yyyy-MM-dd", row2.mtime_string)
I am doing anything wrong? Or is anyother easy way to do this.
Thanks for the reply
I try modified the tmap for mtime but gave me the error.
connecting to socket on port 3691
connected
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method Date(Long) is undefined for the type Testing1
at etl.testing1_0_1.Testing1.tFileProperties_1Process(Testing1.java:958)
at etl.testing1_0_1.Testing1.runJobInTOS(Testing1.java:1364)
at etl.testing1_0_1.Testing1.main(Testing1.java:1221)
Job Testing1 ended at 10:51 13/05/2015.
I also tried the same for mtime_string gave the below error.
Starting job Testing1 at 10:59 13/05/2015.
connecting to socket on port 3958
connected
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method Date(String) is undefined for the type Testing1
at etl.testing1_0_1.Testing1.tFileProperties_1Process(Testing1.java:1004)
at etl.testing1_0_1.Testing1.runJobInTOS(Testing1.java:1410)
at etl.testing1_0_1.Testing1.main(Testing1.java:1267)
Job Testing1 ended at 10:59 13/05/2015.
If you can give me the detail step how to configure that would be really great.
Umesh, It was my mistake. It works fine with new Date(row2.mtime)
row2 modified_output
mtime --> new Date(row2.mtime)
Got the below result
Starting job Testing1 at 04:17 15/05/2015.
connecting to socket on port 3454
connected
2015-05-03
disconnected
Job Testing1 ended at 04:17 15/05/2015.
----------------
Now i get the Date. Can you help me to compare this output with currentDate.
What i want is to use the "Run If " a subjob if the CurrentDate is equal with the above output. How can i achieve this ?