Skip to Content

how to read and then delete a flat file on job server

hi all,

i have a requirement to read files from a folder on jobserver from a BODS job into an oracle server table.

this job to run once daily.

should read all files available at that moment. [will use wild card to read file names like test*.csv ]

after reading, my BODS job should also delete all the processed files from the folder.

also i should make a note of those file names processed.

can anyone help me with this ?

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • Best Answer
    Posted on Feb 03, 2014 at 12:44 PM

    Create a batch file with the following script and save it as test.bat (for example)

    dir  \\sharedpath\newfolder\*.xls /a-d /b >\\sharedpath\newfolder\test.txt
    

    what the above batch file will do it will read all the xls file names and write to test.txt file .

    now you have the txt file .

    so in BODS create a script with the follwoing code

    print(exec('\\\sharedpath\\newfolder\\test.bat', '', 8));
    sleep(4000);
    

    make sure that above path there is double '\\'

    now create a DF1 as below

    now connect script to DF.

    so when you execute it will run the batch file it will refresh the txt file with updated xls file names in that folder and write to test.txt file .

    and then DF1 will get the file name and write to ZTEST table.

    now you can use this table to read the file names and to load the data.

    Regards,

    Sree


    test.PNG (4.6 kB)
    Add a comment
    10|10000 characters needed characters exceeded

    • I am sorry, you confused me a bit by the way you wrote the find-command 😊.

      If I am not mistaken, the correct syntax for the find-command is:

      find /folder -name 'filename_and_or_wildcard'

      So in your case, it would be:

      find /usr/sap/test1 -name 'TEST*'

      Or as of your notation:

      /bin/sh -c "find /usr/sap/test1 -name 'TEST*'"

      Calling this from a script in DS:

      exec('/bin/sh -c "find /usr/sap/test1 -name \'TEST*\'"',8);

      Or when you put the filename prefix in a global variable:

      $variable = 'TEST*';

      exec('/bin/sh -c "find /usr/sap/test1 -name {{$variable}"',8);

      Good practice when developing script is inserting some debugging statements, like

      print('/bin/sh -c "find /usr/sap/test1 -name {{$variable}"');

      The trace file will show the generated command:

      /bin/sh -c "find /usr/sap/test1 -name 'TEST*'"

      If the command fails, you can copy-and-paste it into your Linux command line and run it manually. That may give you a better understanding of the reason why.

  • author's profile photo Former Member
    Former Member
    Posted on Jan 22, 2014 at 01:31 PM
    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jan 22, 2014 at 12:31 PM

    You can read multiple files in a single dataflow by specifying wildcards in the input file format.

    Add a script at the end of your job for deleting the files. Assuming Windows platform:

    exec('cmd','del <path_name>\\*.csv');

    If you don't have too many files (the output of the exec function is limited to 255 characters!), you could simply put

    print(exec('cmd','dir <path_name>\\*.csv'));

    in the same script to write the names of your files to the DS trace file before deleting them. .

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Sep 19, 2014 at 05:41 AM

    thanks for all the replies.

    this is how we resolved it.

    script to move a file after processing

    exec('/bin/sh', '-c "mv /test/{$GV_FILENAME} /test//PROCESSED/{$GV_FILENAME} "',8)

    srcipt to delete a file

    exec('/bin/sh','-c "find /test/'||FILENAME||' -delete"',8)

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.