One Star

Component tFileDelete cannot delete file created by tFileOutputExcel

Hello,
I am trying to delete files created with the component tFileOutputExcel depending
on a condition (deleteIfEmpty), but they cannot be deleted.
To simplify this sample, I substituted the component deleteIfEmpty by the component
tFileDelete, and deactivated deleteIfEmpty (see image).
Looking at the flow, all created files (with tFileOutputExcel) should be deleted by the tFileDelete
component, but they are not being deleted. It looks like the output file is still opened and cannot
be deleted.
I tried to connect (with "OnOK") the component "set Vars" and "tFileInputExcel_1" and none of
them is working.
Any hints?
- the component deleteIfEmpty should delete the file depending on the number of written rows
(i.e. globalMap.get("tFileOutputExcel_1_NB_LINE"))
- the code responsible for the deletion returns always "file could not be deleted":
java.io.File df = new java.io.File((String)globalMap.get("currentOutputFileName"));
if (df.exists() && df.isFile()) {
if (df.delete()) {
System.out.println("file deleted");
} else {
System.out.println("file could not be deleted");
}
Thanks!
eripet
---
Using...
TOS Version: 2.2.2
Language: Java
12 REPLIES
Employee

Re: Component tFileDelete cannot delete file created by tFileOutputExcel

Hello,
Replace your deleteIfEmpty component by a tJavaFlex.
Put your code in the end part and link it to your tFileOuputExcel with a RunIf.
RunIf condition can be something like globalMap.get("tFileOutputExcel_1_NB_LINE"))>0
Regards,
One Star

Re: Component tFileDelete cannot delete file created by tFileOutputExcel

Hello mhirt,
thanks for your reply, but I am afraid your solution does not work neither.
The output Excel file is at the moment the code is executed (in JavaFlex -> End code) still open. I tried to attach it to different components (set Vars, tFileOutputExcel -see picture above-), but it did not work....
It looks like there is a bug, and the component does not close the files as it should, not even at the end of the whole job...
If I link a tFileDelete component to the showInfo component the file will NOT be deleted. If I check the "fail on Error" box the code throws no exception, as the file is still there and delete() returns only true if the file exists and was deleted or false it it exists and was not deleted.
If thousands of files are to be created by such a job, I can imagine that it would get slower and slower and crash at some stage, as the needed OS ressources are limited!
Can you please take a closer look to this issue?
Thanks!
eripet
Employee

Re: Component tFileDelete cannot delete file created by tFileOutputExcel

You're right.
I tried and even if the file.close() command is sent at the end of the component tFileOutputExcel, before the call to the delete, the file.delete() command return false.
Same tJavaFlex in another independant job works.
Can you add a bugtracker entry for this problem ? I think it's related to the API used by the tFileOutputExcel.
Thanks for your support.
One Star

Re: Component tFileDelete cannot delete file created by tFileOutputExcel

Hello mhirt,
thanks for your reply.
New bug related to this issue opened: 2558
Thnx again!
eripet
One Star

Re: Component tFileDelete cannot delete file created by tFileOutputExcel

New bug related to this issue opened: 2558

This may not be a bug. Although you do say " the component does not close the files as it should, not even at the end of the whole job..." it does not seem to be the case in other contexts: as I describe it in http://www.talendforge.org/forum/viewtopic.php?id=11239 you can only touch the generated Excel file in a different subjob. Let me know.
One Star

Re: Component tFileDelete cannot delete file created by tFileOutputExcel

Hello,
I've somewhat the same issue, i'm triggering an error on my database connection and in that case i don't want any file generated. Yet talend still generates an empty file.
I cannot just check the "don't generate empty file' as some report can be empty.
I just want to have no report when there is a java error and i cannot find how to do it, because the file is opened until the end of the job and i cannot delete it or anything...
One Star

Re: Component tFileDelete cannot delete file created by tFileOutputExcel

Long Path Tool helped me in this situation. http://PathTooDeep.com
One Star

Re: Component tFileDelete cannot delete file created by tFileOutputExcel

Why not you are trying long path tool? Long Path Tool helped me in this situation. http://PathTooDeep.com
One Star

Re: Component tFileDelete cannot delete file created by tFileOutputExcel

Hi,
I am using temp space as a my disk for lookup so it is creating so many oracle files in that space when job failed any reasong those files and folder I am trying to delete but it is not deleting folder.
I tried the below senarios.
onSubjobOk
tPostJob->tOracleClose>tFileExist->tFileDelete
this is using for only if job logging purpose--tLogCatcher>tsendMailonComponetOk->tFileDelete
tFileDelete<-onSubjobOk<tLogCatcher->tsendMail
Please let me know as soon as possibel.
Thanks
Narendharr
Moderator

Re: Component tFileDelete cannot delete file created by tFileOutputExcel

Hi namaravaadi,
Is there any error printed on console when you check out "Fail on error" option in TalendHelpCenter:tFileDelete component? Would you mind uploading your whole job design screenshot into forum so that we can get your situation more precisely.
Best regards
Sabrina
--
Don't forget to give kudos when a reply is helpful and click Accept the solution when you think you're good with it.
One Star

Re: Component tFileDelete cannot delete file created by tFileOutputExcel

Hi,
I've encountered a similar problem:
I use tFileInputPositional to read data from a file, tPostgresqlOutput (with Die on error option) to write them to database and a tPostJob for moving (tFileCopy with Remove source file option) the file to another directory at the end of the job
tPostJob works as finally in Java so once tPostgresqlOutput fails it is executed anyway (and this is what I want), but in such case I got the following error:
The source file could not be removed from the folder because it is open or you only have read-only rights.
Can you help me?
Best regards,
Pawel
Seventeen Stars

Re: Component tFileDelete cannot delete file created by tFileOutputExcel

Mostly it is a matter of job design. E.g. if you try to delete the file while the component has not reached its end state.
Could you show us your job design?
To be sure to be able to delete the file use the OnSubjobOk trigger from the subjob writing into the file to call the next subjob in which you delete the file.