Search code examples
c#.nettemporary-files

Deleting Created Temp FIles


In C# or Jscript.NET is it necessary (or better to) delete files created in the folder returned by System.IO.Path.GetTempPath() or is it acceptable to wait for the system to delete them (if this ever happens)?


Solution

  • In terms of how your program will work, it makes no difference.

    The issue is one of cluttering the filesystem with many files in a folder - the more files in a folder, the slower it will be to read it.

    There is also a chance of running out of disk space if the files are not deleted.

    In general, if your software creates temporary files, it should cleanup after itself (that is, delete the files once they are no longer in use).