I have a zipped file in specific folder on server, I have to unzip that file into the folder and then Load it into Database using Business Objects Data Services.
The challange is the name of the file is dynamic.
eg. All apps by name and operating system_364259_20_January_2012_00_22_41_324.csv.
The file name includes Date which will change every day. eg. 20 January 2012 in the above case, I have to extract the date from the file name and insert it into table(I can do it by using di_filename).
First I am checking the file is exists of not by using file_exists function of bods by following code.
Unfortunately the file_exists function does not recognise wildcards in the file name. Another way you can do this is to create a dummy dataflow which reads from your file format object into a template table. The file source allows wildcards and in the file source options there is a setting under ‘Source Information’ called ‘Include file name column’. Set this to ‘Yes’ and then you can specify the properties of a column that will be included in the output schema and will contain the actual file name of all the files found matching your wildcard. If you have only this output field and check the ‘Distinct rows’ then you will just get one row with the file name matching the wildcard (or an empty table if no file exists). You can then use the SQL function in a script after the dataflow to query the template table and get the actual filename. If you need to keep checking until a file(s) is found then just put the dataflow and script inside a WHILE loop.
But please note that if the file has thousands of rows you may need to add a relevant WHERE clause to reduce the rows read from the file if it exists, but this WHERE clause has to be such that it will read at least 1 row if the file exits, otherwise your target file may be blank even if a file exists.
There may be a better way to do this, but it’s the only other way I can think of right now.
Regarding unzipping the file you will need to find a command-line unzip program, there are free apps available. Then you can either build a batch file and then execute the batch file from DS using the EXEC function in a script, or if you only have the one command line to perform the unzip then you can specify it directly in the EXEC function.