Skip to Content
author's profile photo Former Member
Former Member

Delete a flat file using script in BODS

Hi,

I have 9 target files in my network drive/folder. out of which 2 are having data. other 7 files dont have data except headers.

can any one help me how to delete those empty files which are having only headers from the network folder.

How to acheive this using BODS?

Any help appreciated.

Regards

Krishna Mohan

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

6 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Aug 23, 2016 at 09:42 AM

    Steps for deleting the files with no data in outbound folder:

    Steps 1: Declare variables $G_TOTAL_ROWS (data type as int), $G_VALUE (data type as int)

    Step2: create a script after the dataflow where you are creating the multiple files.

    Step3: Write the below script under script_file_deletion

    $G_TOTAL_ROWS = total_rows('DATASTORENAME.DBO.FIRSTTABLENAME);

    print('Total records for FIRST_TABLE is :');

    print($G_TOTAL_ROWS);

    IF ($G_TOTAL_ROWS < 1)

    $G_VALUE=exec('sh', '-c "rm /Data/FILE_NAME1.txt"', 8);

    #Print('Data does not exist for FILE_NAME1 so file is deleted');

    else

    print('Data Exists for FILE_NAME1);


    the above code works for LINUX not for windows.


    Step4: Repeat code for other files.

    Step5: Check whether file is deleted or not in the folder


    Note: above script works for Linux platform.


    Regards

    Krishna Mohan

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Aug 18, 2016 at 08:35 AM

    Hi Krishna,

    Hope the following reference will help you fulfill your requirement.

    How to avoid empty file generation in BODS | SCN

    Hope this helps.

    And if you need any specifics regarding implementing for your scenario..please do let me know

    Thanks,

    AJ

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Aug 22, 2016 at 11:16 AM

    Hi,

    Can you try below syntax,it might be helpful to you .Give the flat file path in YOur shared path

    exec('cmd','del \\\ your shared path\archive\mpi\*.xml',8);



    Thanks

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      You can use following script which I have mentioned earlier for identifying the size of the file & then deleting:

      If SAP Data Services is hosted on Linux/AIX you can write shell script

      if [ `wc -l filename` -gt 0]

      rm filename

      If SAP Data Services is hosted on Windows, you can write bat file

      FINDSTR /R /N "^.*$" filename.txt | FIND /C ":"

      You have to store file names in a file and then use while loop to read the file name one by one.

      Thanks

  • Posted on Aug 17, 2016 at 01:05 PM

    write a windows bat file to check if excel file with header is empty. Call the bat file in exec() in BODS.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Aug 17, 2016 at 06:18 PM

    Hello Krishna,

    If SAP Data Services is hosted on Linux/AIX you can write shell script

    if [ `wc -l filename` -gt 0]

    rm filename

    If SAP Data Services is hosted on Windows, you can write bat file

    FINDSTR /R /N "^.*$" filename.txt | FIND /C ":"

    You have to store file names in a file and then use while loop to read the file name one by one.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Aug 18, 2016 at 08:00 AM

    Krishna

    It will get complicated if you write the logic to delete the empty excel files. Data Services can process multiple excel files and you should not worry about the empty ones.

    You can include DI_FILENAME for each excel file. The excel containing the data will be loaded and the DI_FILENAME will be populated.

    Hope this simplifies your work 😊

    Regards

    Arun Sasi


    pastedImage_1.png (17.6 kB)
    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.