Skip to content

Instantly share code, notes, and snippets.

@ArnisL
Created December 15, 2010 14:59
Show Gist options
  • Save ArnisL/742040 to your computer and use it in GitHub Desktop.
Save ArnisL/742040 to your computer and use it in GitHub Desktop.
temp_directory.cs
using System;
using System.IO;
public class TempDirectory:IDisposable{
private readonly string _path;
public TempDirectory(){
var path=Path.Combine(Path.GetTempPath(),Path.GetRandomFileName());
Directory.CreateDirectory(path);
_path=path;
}
public void Dispose(){
Directory.Delete(_path,true);
}
public static implicit operator string(TempDirectory m){
return m._path;
}
}
using(var tempDir=new TempDirectory()){
//something...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment