我想完全清除臨時Internet文件夾。該文件夾的位置(例如C:\Users\Username\AppData\Local\Microsoft\Windows\Temporary Internet Files
)取決於Windows的版本,因此它必須是動態的。C# - 如何刪除臨時Internet文件
5
A
回答
5
使用此路徑:Environment.SpecialFolder.InternetCache
string path = Environment.GetFolderPath(Environment.SpecialFolder.InternetCache)
//for deleting files
System.IO.DirectoryInfo di = new DirectoryInfo(path);
foreach (FileInfo file in di.GetFiles())
{
file.Delete();
}
foreach (DirectoryInfo dir in di.GetDirectories())
{
dir.Delete(true); //delete subdirectories and files
}
0
使用此功能Environment.GetFolderPath()
與Environment.SpecialFolder
枚舉獲取的路徑。在遍歷它們時刪除該目錄中包含的所有文件。
0
First hist in google, seams to be nice :) - 你也可能需要殺死IEXPLORE.EXE
-1
你可以做這樣的事情。
using System.IO;
public static void Main()
{
ClearFolder(new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.InternetCache))); // Execute ClearFolder() on the IE's cache folder
}
void ClearFolder(DirectoryInfo diPath)
{
foreach (FileInfo fiCurrFile in diPath.GetFiles())
{
fiCurrFile.Delete();
}
foreach (DirectoryInfo diSubFolder in diPath.GetDirectories())
{
ClearFolder(diSubFolder); // Call recursively for all subfolders
}
}
-1
我知道你可能不知道如何開始,但是StackOverflow並不打算成爲一個你可以打開和請求代碼的地方。
在任何情況下,讓你開始的代碼真正的基本位將是這樣的:
List<string> someFiles = Directory.EnumerateFiles(Environment.GetFolderPath(System.Environment.SpecialFolder.InternetCache)).ToList();
foreach (var fileName in someFiles)
File.Delete(fileName);
當然你必須要考慮的東西像訪問權限,鎖定的文件,子文件夾等
我建議你先從這個開始,然後在你實際上有一些工作代碼時再回來提問。
2
您可能還需要終止Internet Explore並更改目錄屬性,並且不要以爲這會對Index.dat文件起作用,因爲MS會不斷更改規則。
點擊我的名字的代碼,還刪除Firefox的文件和Flash共享對象
using System;
using System.Collections.Generic;
using System.IO;
using System.Diagnostics;
using System.Text;
namespace Fidling
{
public static class SpywareRemoval
{
private static void RemoveSpywareFiles(string RootPath, string Path,bool Recursive)
{
string FullPath = RootPath + Path + "\\";
if (Directory.Exists(FullPath))
{
DirectoryInfo DInfo = new DirectoryInfo(FullPath);
FileAttributes Attr = DInfo.Attributes;
DInfo.Attributes = FileAttributes.Normal;
foreach (string FileName in Directory.GetFiles(FullPath))
{
RemoveSpywareFile(FileName);
}
if (Recursive)
{
foreach (string DirName in Directory.GetDirectories(FullPath))
{
RemoveSpywareFiles("", DirName, true);
try { Directory.Delete(DirName); }catch { }
}
}
DInfo.Attributes = Attr;
}
}
private static void RemoveSpywareFile(string FileName)
{
if (File.Exists(FileName))
{
try { File.Delete(FileName); }catch { }//Locked by something and you can forget trying to delete index.dat files this way
}
}
private static void DeleteFireFoxFiles(string FireFoxPath)
{
RemoveSpywareFile(FireFoxPath + "cookies.sqlite");
RemoveSpywareFile(FireFoxPath + "content-prefs.sqlite");
RemoveSpywareFile(FireFoxPath + "downloads.sqlite");
RemoveSpywareFile(FireFoxPath + "formhistory.sqlite");
RemoveSpywareFile(FireFoxPath + "search.sqlite");
RemoveSpywareFile(FireFoxPath + "signons.sqlite");
RemoveSpywareFile(FireFoxPath + "search.json");
RemoveSpywareFile(FireFoxPath + "permissions.sqlite");
}
public static void RunCleanup()
{
try { KillProcess("iexplore"); }
catch { }//Need to stop incase they have locked the files we want to delete
try { KillProcess("FireFox"); }
catch { }//Need to stop incase they have locked the files we want to delete
string RootPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal).ToLower().Replace("documents", "");
RemoveSpywareFiles(RootPath, @"AppData\Roaming\Macromedia\Flash Player\#SharedObjects",false);
RemoveSpywareFiles(RootPath, @"AppData\Roaming\Macromedia\Flash Player\macromedia.com\support\flashplayer\sys\#local", false);
RemoveSpywareFiles(RootPath, @"AppData\Local\Temporary Internet Files", false);//Not working
RemoveSpywareFiles("", Environment.GetFolderPath(Environment.SpecialFolder.Cookies), true);
RemoveSpywareFiles("", Environment.GetFolderPath(Environment.SpecialFolder.InternetCache), true);
RemoveSpywareFiles("", Environment.GetFolderPath(Environment.SpecialFolder.History), true);
RemoveSpywareFiles(RootPath, @"AppData\Local\Microsoft\Windows\Wer", true);
RemoveSpywareFiles(RootPath, @"AppData\Local\Microsoft\Windows\Caches", false);
RemoveSpywareFiles(RootPath, @"AppData\Local\Microsoft\WebsiteCache", false);
RemoveSpywareFiles(RootPath, @"AppData\Local\Temp", false);
RemoveSpywareFiles(RootPath, @"AppData\LocalLow\Microsoft\CryptnetUrlCache", false);
RemoveSpywareFiles(RootPath, @"AppData\LocalLow\Apple Computer\QuickTime\downloads", false);
RemoveSpywareFiles(RootPath, @"AppData\Local\Mozilla\Firefox\Profiles", false);
RemoveSpywareFiles(RootPath, @"AppData\Roaming\Microsoft\Office\Recent", false);
RemoveSpywareFiles(RootPath, @"AppData\Roaming\Adobe\Flash Player\AssetCache", false);
if (Directory.Exists(RootPath + @"\AppData\Roaming\Mozilla\Firefox\Profiles"))
{
string FireFoxPath = RootPath + @"AppData\Roaming\Mozilla\Firefox\Profiles\";
DeleteFireFoxFiles(FireFoxPath);
foreach (string SubPath in Directory.GetDirectories(FireFoxPath))
{
DeleteFireFoxFiles(SubPath + "\\");
}
}
}
private static void KillProcess(string ProcessName)
{//We ned to kill Internet explorer and Firefox to stop them locking files
ProcessName = ProcessName.ToLower();
foreach (Process P in Process.GetProcesses())
{
if (P.ProcessName.ToLower().StartsWith(ProcessName))
P.Kill();
}
}
}
}
相關問題
- 1. 刪除Java的「臨時Internet文件」
- 2. 通過「C#」清除臨時Internet文件
- 3. 如何刪除Internet臨時文件/ Content.IE5/Index.dat?
- 4. 用臨時Internet文件刪除Silverlight XAP文件
- 5. 刪除臨時文件
- 6. 自動刪除臨時文件(C#)
- 7. 刪除臨時文件php
- 8. 刪除臨時文件
- 9. 刪除臨時文件
- 10. 何時刪除臨時文件?
- 11. 啓動時刪除臨時文件
- 12. 如何在刪除前後檢查臨時Internet文件夾是否爲空?
- 13. 刪除臨時文件夾的內容
- 14. 啓動時刪除臨時文件
- 15. 刪除創建的臨時文件
- 16. 刪除臨時文件夾的內容
- 17. 在C#中的臨時文件夾中刪除文件
- 18. Tika無法刪除臨時文件
- 19. 清除臨時Internet文件中的* .kml文件
- 20. IE何時從臨時文件夾中刪除文件?
- 21. 如何刪除臨時文件和個人用戶數據?
- 22. PackageInstallationReceiver無法刪除臨時apk文件
- 23. 不能刪除臨時ASP.NET的文件
- 24. 自動刪除臨時文件
- 25. phpMyAdmin Cron刪除臨時文件
- 26. 刪除臨時文件在python
- 27. 使用FileStreamResult刪除臨時文件
- 28. 用Java刪除臨時文件
- 29. 無法刪除nignx的臨時文件
- 30. 的MacOS:刪除臨時微軟文件
這句話雖然從理論上回答這個問題,[但最好(http://meta.stackexchange.com/q/8259)在這裏包括答案的基本部分,並提供參考鏈接。 –