on 05-24-2023 7:05 PM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Nawfal,
Thanks, this works 😉
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
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
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.
Greetings bittu_sharma ,
Please read the documentation
Connection options for OAuth 2.0 (2-legged) authorization schema
BR,
Joe
User | Count |
---|---|
70 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.