slet filer permanent.
HejsaHvordan sletter jeg filer permanent. Det vil sige uden at filerne ryger i Recycle Bin (Skraldespand)?
Nedenstående kode flytter samtlige filer i Recycle Bin. Jeg ønsker at slette filerne permanent... How?
/henrik
// Delete all files. Leave Directory empty
public void DeleteFilesInDirectory(string path)
{
// Delete all files from the Directory
if (Directory.Exists(path))
{
foreach (string file in Directory.GetFiles(path))
{
System.IO.File.Delete(file);
}
foreach (string directory in Directory.GetDirectories(path))
{
DeleteDirectoryWithFiles(directory, "");
}
}
}
// Delete all files and the corresponding Directortory.
public void DeleteDirectoryWithFiles(string path, string notDeletePath)
{
// Delete all files from the Directory
if (Directory.Exists(path))
{
foreach (string file in Directory.GetFiles(path))
{
System.IO.File.SetAttributes(file, FileAttributes.Normal);
System.IO.File.Delete(file);
}
foreach (string directory in Directory.GetDirectories(path))
{
try
{
DeleteDirectoryWithFiles(directory, "");
}
catch (Exception ex)
{
log.ErrorLog(logpath, "DeleteDirectoryWithFiles failed. Path: " + path);
log.ErrorLog(logpath, ex.ToString());
}
}
}
// Delete a empty directory
if (Directory.Exists(path) && path != notDeletePath)
Directory.Delete(path);
}