src/MajungaLibrary/Helpers/FileHelper.cs
/// <summary>
/// Delete files in Directory that are older than 15 mins
/// </summary>
/// <param name="path">Directory Path</param>
Delete files in Directory that are older than 15 mins
Delete files in Directory that are older than 15 mins
public static void DeleteExpiredFile(string path)
        {
            Console.WriteLine("Deleting Expired files");
            foreach (var file in Directory.GetFiles(path))
            {
                var fileInfo = new FileInfo(file);
                Console.WriteLine($"Trying to delete {fileInfo.Name}");
                if (fileInfo.CreationTime.AddHours(1) < DateTime.Now && !fileInfo.Name.Contains("test.txt"))
                {
                    try
                    {
                        fileInfo.Delete();
                        Console.WriteLine($"Deleted {fileInfo.Name}");
                    }
                    catch (UnauthorizedAccessException)
                    {
                        Console.WriteLine($"Failed to delete {fileInfo.Name}");
                        continue;
                    }
                }
            }
        }
public static void DeleteExpiredFile ( string path ) { Console . WriteLine ( " " ) ; foreach ( var file in Directory . GetFiles ( path ) ) { var fileInfo = new FileInfo ( file ) ; Console . WriteLine ( $" Trying to delete  { fileInfo . Name } " ) ; if ( fileInfo . CreationTime . AddHours ( 1 ) < DateTime . Now && ! fileInfo . Name . Contains ( " " ) ) { try { fileInfo . Delete ( ) ; Console . WriteLine ( $" Deleted  { fileInfo . Name } " ) ; } catch ( UnauthorizedAccessException ) { Console . WriteLine ( $" Failed to delete  { fileInfo . Name } " ) ; continue ; } } } }
Delete files in Directory that are older than 15 mins
Delete files in Directory that are older than 15 mins
path
string
None