Page 1 of 3

Deletion of output file

Posted: Wed Oct 11, 2006 8:30 am
by Latha1919
Hi,

I have a Job writing data to four .csv files (in the Sequential file stages) at the end. I do have constraints defined for these satges.

Even though there's no data written to the file, that particualr file is still created in the folder. How do I overcome this issue? I would like the file to be erased, when there's no data written to it.

Please advise.

Thanks

Posted: Wed Oct 11, 2006 8:37 am
by chulett
Yup, that's the way it works. When the stage is 'started' the file is opened and created as a zero byte file if needed. There's no 'only create it if I write to it' option.

You'll need to do something after job, a script or batch file or routine that checks for a zero size and deletes if it is.

Posted: Wed Oct 11, 2006 8:38 am
by kumar_s
File will be definetly create when you have the link.
Either you need to pre process or Post process for this.
Either you can check for the size and remove it from the OS or pass different value to the parameter to the job if the file need not to be create at some specific condition, say /dev/null.

Posted: Wed Oct 11, 2006 9:13 am
by Latha1919
There's no option of After-stage routine for seuential file stage.

Posted: Wed Oct 11, 2006 9:14 am
by DeepakCorning
What about the after job subroutine??

Posted: Wed Oct 11, 2006 9:24 am
by DSguru2B
You are correct. There is no option. You will have to write you own routine to detect a file with size zero and issue a delete command at the os level.

Posted: Wed Oct 11, 2006 9:24 am
by chulett
You could do it 'after stage' from the transformer that feeds the Sequential stage, but I did specifically say 'after job'.

Posted: Wed Oct 11, 2006 9:32 am
by Shree0410
The simplest way is to create a script file on the OS to have the logic to delete file if the file size is 0 or record count is 0 and execute this script in the after job routine.

Posted: Wed Oct 11, 2006 9:34 am
by DSguru2B
Here, Ray created something like this a while back. Take a look
viewtopic.php?t=101158.

Posted: Wed Oct 11, 2006 9:57 am
by Latha1919
I can go for After Job routine. How do I get the size of the file. o/s is Windows. Secondly, I am finding 2kb file size even though no records are written to the file.. it's containing the column names of the file (.csv)

Posted: Wed Oct 11, 2006 10:13 am
by DSguru2B
You can go to the sequential file stage properties and uncheck "First line is column names" option. That will truely keep the file empty if its empty.
Look at Rays routine. He is using the STATUS function to determine the file size. STATUS() function returns different information in a dynamic array. The size info is present in the 6th entry in the array.

Posted: Wed Oct 11, 2006 10:31 am
by Latha1919
I need to have the column names in the file.

Posted: Wed Oct 11, 2006 10:39 am
by DSguru2B
well then instead of checking for 0 bytes, check for 2kb. And if a file is 2kb or less, then delete it.

Posted: Wed Oct 11, 2006 10:44 am
by Latha1919
DSguru2B,

Please let me know, where do I find Status function created by Ray to determine the file size.

Posted: Wed Oct 11, 2006 10:57 am
by kris007
If you click the link provided by DSGuru in one of his earlier posts, it will lead you to that thread where in second page you can find a routine written by Ray. I remember doing something similar in one of my earlier projects but I can't dig that routine at the moment. It's possible when I get back home and shall try doing that.