cancel
Showing results for 
Search instead for 
Did you mean: 

Delete files older than x days using BODS inbuilt function.

bittu_sharma
Explorer
0 Kudos

Hi ,

Help!!

can we delete files older than x days using BODS inbuilt function-

file_delete( '\\\\sharedpath\\test_file\\*.txt');

this line is deleting all the txt files inside the given path.

i just want to delete 30 days old files.

or any other option to delete files older than x days using any BODS inbuilt function.

Regards,

Bittu

AlexGourdet
Product and Topic Expert
Product and Topic Expert
0 Kudos

Thank you for visiting SAP Community to get answers to your questions. Since this is your first question, I recommend that you familiarize yourself with Community Q&A, as the overview provides tips for preparing questions that draw responses from our members.

Should you wish, you can revise your question by selecting Actions, then Edit.

By adding a Picture to your profile you encourage readers to respond.

View Entire Topic
Nawfal
Active Participant

Hi Bittu,

Executing OS command via BODS exec() function as described by joseph_muiruri might be easier, especially in Linux. However if you are determined to only use BODS built-in function then this solution can be of help to you.

1- Create these global variables at the job level:

2- In a script write the following:

$G_FilePath='//sharedpath/test_file/*.txt'; #The network path
$G_RetentionDays =30; #Retention period in days
$G_FileCounter=1; #Initialiase loop counter

print(wait_for_file( $G_FilePath, 0, 0,-1,$G_FileList, $G_FileCount ,',')); #produce list of files in the given path with their count
print('Files found in the given path:'|| $G_FileList); #print list
print('No of files in path: '||$G_FileCount); #print how many

while ($G_FileCounter<=$G_FileCount) #check each file in the path  for its modified date
 begin
    $G_FileName=print(word_ext( $G_FileList,$G_FileCounter,',')); #Check one file at a time
    $G_FileChangedDate =print(get_file_attribute(  $G_FileName,'date_modified'));#get file date attribute, can be changed to data_created
    $G_FileName=replace_substr( $G_FileName,'//','\\\\');#Adjust the UNC path to suite file_delete function
    if ($G_FileChangedDate <sysdate() - $G_RetentionDays)
      begin 
         print( file_delete( $G_FileName));#delete old file
	 print('File :'||$G_FileName||' deleted');
      end
    $G_FileCounter=$G_FileCounter+1;
 end
bittu_sharma
Explorer

Hi Nawfal,

Thanks, this works 😉

bittu_sharma
Explorer
0 Kudos

Hi Nawfal,

Is there any restriction for file count ?

because i have 1.2 lakh files approx. but the code is not deleting more than 40 files in a single run.

Would be very helpful if we can delete all the files for given time range.

Regards,

Bittu

Nawfal
Active Participant

Hi,

There shouldn't be a limit in the count, but it seems that the variable FileList length is too small to hold all your files path and name. Try to increase the length and check the trace log what gets printed in this list and whether all your files are listed.

Thanks

Nawfal

bittu_sharma
Explorer
0 Kudos

Hi Nawfal,

Great !

This worked.

Thank You So much 🙂

bittu_sharma
Explorer
0 Kudos

Hi Nawfal,

Script for deleting files is working as expected thank you so much for that.

i have a concern that script is not deleting the file which is having the file extension in the file name itself.

example -file Test_839_vs30_csv_20230220_063003.ctl is not deleting,

but Test_839_vs30_csv_20230220_063003 can delete.

can you please help.

Regards,

Bittu

bittu_sharma
Explorer
0 Kudos

Hi Nawfal/Joseph,

Good Day!!

Request you please help and suggest..

if we can use OAuth 2.0 authorization schema for REST API webservice for establishing a Datastore connection in SAP BODS if yes then how if no then why.

Regards,

Bittu

Nawfal
Active Participant
0 Kudos

Hi,

I suggest you create a brand new question in the forum with more info of what you are trying to achieve (give example if possible).

Thanks

bittu_sharma
Explorer
0 Kudos

Hi Nawfal,

I have created two questions there in the forum.

How to create datastore for REST webservice using OAuth 2.0 in SAP BODS. | SAP Community

Kindly check and respond.

Thanks.

jmuiruri
Product and Topic Expert
Product and Topic Expert
0 Kudos

Greetings bittu_sharma ,

Please read the documentation

Connection options for OAuth 2.0 (2-legged) authorization schema

BR,

Joe