I created a service which will move backup to a disk on daily basis.
But before moving the backup i need to check the available space of the disk. If available space is less than 1 TB need to delete the oldest backup folder from the disk and then continue the backup
I got the available space using below code
DriveInfo driveInfo = new DriveInfo(@"H:");
long FreeSpace = (((driveInfo.AvailableFreeSpace) / 1024) / 1024 / 1024) / 1024;
Now i need to check FreeSpace
value is less than 1
if(FreeSpace < 1)
{
//need to delete the folder in the path H:\backup\
//whose created date is the oldest
}
eg:-
> If available space is less than 1 TB and H:\backup\ contain 3 folder
> 19062017 -- created on 19/06/2017
20062017 -- created on 20/06/2017
21062017 -- created on 21/06/2017
> We need to delete the folder 19062017 with its content
How to achive the same in C#