2011-06-29 14 views
5

मैं अस्थायी इंटरनेट फ़ाइलों फ़ोल्डर को पूरी तरह से साफ़ करना चाहता हूं। फ़ोल्डर का स्थान, उदाहरण के लिए, C:\Users\Username\AppData\Local\Microsoft\Windows\Temporary Internet Files, विंडोज के संस्करण पर निर्भर करता है, इसलिए इसे गतिशील होना चाहिए।सी # - अस्थायी इंटरनेट फ़ाइलों को कैसे हटाएं

उत्तर

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.SpecialFolder गणन के साथ इस समारोह Environment.GetFolderPath() का उपयोग करने से पथ प्राप्त करें। उस निर्देशिका में निहित सभी फ़ाइलों को हटाते समय हटाएं।

0

First hist in google, seams to be nice :) - भी आप शायद iexplore.exe

+0

इस जबकि निकालता है सैद्धांतिक रूप से इस सवाल का जवाब कर सकते हैं के लिए मेरे नाम पर क्लिक करें [यह बेहतर होगा] (http://meta.stackexchange.com/q/825 9) यहां उत्तर के आवश्यक हिस्सों को शामिल करने के लिए, और संदर्भ के लिए लिंक प्रदान करें। –

-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 
    } 
} 
+0

क्या आपने और निमा कॉपी वर्बैटिम [वही खोज परिणाम] (http://forums.asp.net/t/1563686.aspx/1)? यदि आप कहीं से कॉपी करते हैं तो आपको एट्रिब्यूशन प्रदान करना चाहिए। – slugster

+0

मुझे इसके बारे में पता नहीं है, लेकिन मैं यहां से कोड लेता हूं: http://www.geekpedia.com/code166_Delete-All- समकालीन- इंटरनेट- फ़ाइल- Of-IE.html – JAiro

-1

मैं समझता हूँ कि आप आरंभ करने के लिए कैसे पता नहीं है, लेकिन StackOverflow एक जगह है जहाँ आप बस छोड़ कर देते हैं और अनुरोध कोड कर सकते हैं होने के लिए इरादा नहीं है।

किसी भी मामले में, कोड की एक वास्तविक बुनियादी बिट आप आरंभ करने के लिए यह होगा:

List<string> someFiles = Directory.EnumerateFiles(Environment.GetFolderPath(System.Environment.SpecialFolder.InternetCache)).ToList(); 
foreach (var fileName in someFiles) 
    File.Delete(fileName); 
बेशक

आप पहुँच अनुमतियाँ, लॉक्ड फाइल्स, सबफ़ोल्डर, आदि

की तरह बातों पर विचार करने के लिए है

मैं सुझाव दूंगा कि आप इसके साथ शुरू करें, फिर वास्तव में कुछ प्रश्नों के साथ वापस आएं जब आपके पास वास्तव में कुछ कार्य कोड है।

2

आपको प्रक्रिया को इंटरनेट एक्सप्लोर करने और निर्देशिका विशेषताओं को बदलने की प्रक्रिया को भी मारने की आवश्यकता हो सकती है और यह नहीं सोचें कि यह index.dat फ़ाइलों के लिए काम करेगा क्योंकि एमएस नियमों को बदलते रहेंगे।

, कोड है कि यह भी फ़ायरफ़ॉक्स फ़ाइलें और फ्लैश साझा वस्तुओं

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(); 
      } 
     } 
    } 
} 
संबंधित मुद्दे