Created
January 25, 2011 04:36
-
-
Save martinbowling/794519 to your computer and use it in GitHub Desktop.
TempCache Code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IO; | |
namespace Tables06 | |
{ | |
public class TempCache | |
{ | |
public readonly static string BaseDir = Path.Combine (Environment.GetFolderPath (Environment.SpecialFolder.Personal), ".."); | |
public readonly static string PicDir = Path.Combine (BaseDir, "Library/Caches/Pictures/"); | |
public readonly static string TmpDir = Path.Combine (BaseDir, "tmp/"); | |
public TempCache () | |
{ | |
} | |
public void CleanTemp() | |
{ | |
foreach (string f in Directory.GetFiles (TmpDir, "*.jpg")) | |
File.Delete (f); | |
} | |
public void CleanPic() | |
{ | |
foreach (string f in Directory.GetFiles (PicDir, "*.jpg")) | |
File.Delete (f); | |
} | |
public void CleanCache() | |
{ | |
CleanTemp(); | |
CleanCache(); | |
} | |
public long TmpDirSize() | |
{ | |
long totalSize = 0; | |
System.IO.DriveInfo[] drives = System.IO.DriveInfo.GetDrives(); | |
foreach (System.IO.DriveInfo drive in drives) | |
{ | |
if (drive.Name.ToString() == "/") | |
{ | |
if (drive.IsReady) Console.WriteLine(drive.AvailableFreeSpace); | |
System.IO.DirectoryInfo dirinfo = drive.RootDirectory; | |
System.IO.DirectoryInfo[] dirs = dirinfo.GetDirectories(TmpDir); | |
foreach (var d in dirs) | |
{ | |
System.IO.FileInfo[] files = d.GetFiles(); | |
foreach (var file in files) | |
{ | |
totalSize += file.Length; | |
} | |
} | |
} | |
} | |
return totalSize; | |
} | |
public long PicDirSize() | |
{ | |
long totalSize = 0; | |
System.IO.DriveInfo[] drives = System.IO.DriveInfo.GetDrives(); | |
foreach (System.IO.DriveInfo drive in drives) | |
{ | |
if (drive.Name.ToString() == "/") | |
{ | |
if (drive.IsReady) Console.WriteLine(drive.AvailableFreeSpace); | |
System.IO.DirectoryInfo dirinfo = drive.RootDirectory; | |
System.IO.DirectoryInfo[] dirs = dirinfo.GetDirectories(PicDir); | |
foreach (var d in dirs) | |
{ | |
System.IO.FileInfo[] files = d.GetFiles(); | |
foreach (var file in files) | |
{ | |
totalSize += file.Length; | |
} | |
} | |
} | |
} | |
return totalSize; | |
} | |
public bool HasFreeSpace() | |
{ | |
System.IO.DriveInfo[] drives = System.IO.DriveInfo.GetDrives(); | |
foreach (System.IO.DriveInfo drive in drives) { | |
if (drive.Name.ToString() == "/") | |
{ | |
if (drive.IsReady) { | |
if (drive.AvailableFreeSpace > 1000) | |
return true; | |
else | |
return false; | |
} | |
} | |
} | |
return false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment