I am currently working on a c# program where I check the creation time of a file and delete it if the file is older than 2 days. I have the following code snippet that shoul
I guess an additional problem must be in
File.Delete(string.Format("{0}/{1}", directory, file));
Your file is of type FileSystemInfo. Maybe you wanted to use file.Name. Example: let's say directory is "c:\" and file points to "c:\myfile.log", your code will try to delete "c:/c:\myfile.log". It's hard for me to guess what exactly you have in these variables.
Correct replacement is suggested by @HenkHolterman:
file.Delete();