Programmatically Copy Files from 'Temporary In

2019-01-25 18:55发布

问题:

I need to copy all images from Temperary Internet Files to some other directory. I tried using below code

string[] IeImageFiles = Directory.GetFiles(
  Environment.GetFolderPath(Environment.SpecialFolder.InternetCache).ToString());

the problem is that GetFiles method returns only few files. Whereas I can see many files in the same folder when I browse through internet explorer 'View Files'(IE options -> General Tab -> Settings ->Temporary internet Files).

I need to know the physical path so as to query the directory and get the files. How to achieve that. Any help greatly appreciated.

回答1:

The files you see when you do 'View Files' (IE options > General Tab > Settings > Temporary internet Files) are not actually files that are located on disc directly in the Temporary Internet Files folder.

There's a hidden folder inside that location called Content.IE5, and that will contain several randomly named folders with the actual temporary internet files inside them.

To get a list of them you can do this:

var path = Path.Combine(
    Environment.GetFolderPath(Environment.SpecialFolder.InternetCache),
    "Content.IE5");
string[] files = Directory.GetFiles(path, "*", SearchOption.AllDirectories);

For more information check out A Primer on Temporary Internet Files by Eric Law.