I’ve created a job that deletes files that aren’t used. The problem is the method taking up alot of time and I want to know if this is the correct way of deleting a file?
(we want to free up space on the disk so its important that the files get deleted from the disk as well)
private void DeleteUnusedFilesFromFolders(FolderCollection folders)
{
foreach (var subFolder in folders)
{
foreach (var fileId in subFolder.FileIDs)
{
var file = MediaArchiveFile.GetFile(subFolder.Files.FileIDs.FirstOrDefault(),
Solution.Instance.SystemToken);
if (!IsFileBeingUsed(file))
{
//delete file
file.Delete(Solution.Instance.SystemToken);
}
}
}
}
private bool IsFileBeingUsed(MediaArchiveFile file)
{
var searchResult = ModuleMediaArchive.Instance.SearchService.FindFilePointers(file.ID);
return searchResult.Count > 0;
}
Litium version: 5