Quantcast
Channel: SCN : Blog List - All Communities
Viewing all articles
Browse latest Browse all 2548

Delete Files Older than N days(UNC Path) in Data Services

$
0
0

There are scenarios where you are required to delete files older than certain days from archive folder using Data Services. Below script will make that happen which will work on UNC paths.

 

Replace 10 with number of days files to be kept, you can use variable. Any files older than this will be deleted.

 

$GV_FILES_DELETED =FN_DOS('PushD "[$GV_ARCHIVE_DIRECTORY]" && (forfiles -s -m *.* -d -10 -c "cmd /c echo @file") & PopD');
Print( 'Files that will be deleted from Archive folder are ' || $GV_FILES_DELETED );
$GV_FILES_DELETED =FN_DOS('PushD "[$GV_ARCHIVE_DIRECTORY]" && (forfiles -s -m *.* -d -10 -c "cmd /c del /q @path") & PopD');
Print('Files Older than ' || $GV_FILE_RETENTION_DAYS || ' days are being deleted now');

FN_DOS will have following code

aa.png


Viewing all articles
Browse latest Browse all 2548

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>