Cleanup commonFilesDirectory

I need to clean up the commonFilesDirectory We have removed a lot of product and content with sql scripts and now we have a lot of files not in use.
Do you have any recommendations about how to solve this?
Can I get a list of all files i use? [Media].[File]? or is there more references to files?

Litium version: 6.1.1


For product the data is only stored in the database except from the search index that you can rebuild from BO\Settings\Search index.

For every file for the media they ave a column with named BlobUri that is the reference for the file that should be removed. And dependent how the URI is created it points to different directory in the common files folder. If the schema does not contain the work +storage then the file is below the Storage and maybe also in Storage_Cache folders and otherwise in the media folder.

If you want to trigger the deletion from the database you can do the background job that also is used and deleting media when files are removed with the API.

Create a class in your project as

using System;
using System.Threading.Tasks;
using Litium.Blobs;
using Litium.Scheduler;

namespace Litium.Blobs
    public class BlobCleanupJob
        private readonly SchedulerService _schedulerService;
        private readonly BlobService _blobService;

        public BlobCleanupJob(
            BlobService blobService,
            SchedulerService schedulerService)
            _blobService = blobService;
            _schedulerService = schedulerService;

        public Task Cleanup(Uri uri)
            var container = _blobService.Get(uri);

            return Task.CompletedTask;

The sql will be like the following, remember to change the parameters in the first section of the script

		@username NVARCHAR(100) = '',
		@cleanupJobClassType NVARCHAR(250) = 'Litium.Blobs.BlobCleanupJob, Litium.Application.Mvc'

DECLARE @userId UNIQUEIDENTIFIER = (SELECT SystemId FROM Security.PasswordLoginInfo WHERE Id = @username);
INSERT INTO [Scheduler].[ExecutionInfo] (SystemId, DataJson)
SELECT SystemId, '{"arguments":[{"$type":"System.Uri, System, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089","$value":"' + 
	BlobUri + '"}],'+
	'"declaringType":"' + @cleanupJobClassType + '",'+
	'"methodArgumentTypes":["System.Uri, System, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089"],'+
	'"claims":[{"type":"","value":"' + 
	@username + '"},{"type":"","value":"' + 
	CONVERT(NVARCHAR(36), @userId) + '"},{"type":"","value":"Litium Identity"}]}}' 
FROM Media.[File] where SystemId = @fileSystemId
INSERT INTO [Scheduler].[ScheduledJob] (SystemId, CreatedAtUtc, CreatedBy, QueueAtUtc, [ExecutionInfoSystemId], [ExpireAtUtc])
SELECT NEWID(), GETUTCDATE(), @username, GETUTCDATE(), SystemId, GETUTCDATE() + 100 FROM Media.[file] where SystemId = @fileSystemId