我想读取Temporary Internet Files下的文件,列出所有文件名,怎么读,按常规方法读不到,
我在网上找的的方法,但读出后的文件名并不是在windows下看到的名称,而是一个连接地址,为什么?怎么读取文件名称,求高人指点?网上找的方法:
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls,WinSock,StrUtils;
type
TindexdatHead=packed record //index.dat 文件头结构
version:array [0..32]of char;
entryaddr:Word;
unkown:array[0..48] of char;
end;
TblockDataHead=packed record//4字节
Flags:array [0..3]of Char;
datasize:Word;
unknown1:word;
// Visitetime:TDateTime;
end;
TblockUnkown=packed record //76字节
HaveUrl:DWORD;
unknowned:array [0..71]of char;
end;
Tquedata=packed record
unknowned1:DWORD;
unknowned2:DWORD;
visitetime:integer;
unknowned3:array [0..7] of char;
end;type
TForm2 = class(TForm)
Panel1: TPanel;
Button1: TButton;
Label1: TLabel;
Label2: TLabel;
Memo1: TMemo;
Button2: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
function UniCode2GB(S : String):String; public
{ Public declarations }
end;var
Form2: TForm2;implementation{$R *.dfm}procedure TForm2.Button1Click(Sender: TObject);
const Historydatfile='\Local Settings\Temporary Internet Files\Content.IE5\index.dat';// %USERPROFILE%
VAR indexfile:Thandle;
indexhead:TindexdatHead;
readcount:integer;
tmp:_OFSTRUCT;
blockhead:TblockDataHead;
data:array of char;
tmpstr:string;
strFlags:string;
quedata:Tquedata;
blockunkwnow:TblockUnkown;
keywordFounded:boolean;
fileposition:Cardinal;
indexfilesize:Cardinal;
visitetime:string;tmpint:integer;
visitetimeh,visitetimel:word;
userpath:string;
begin
userpath:=GetEnvironmentVariable('USERPROFILE');
indexfile:=windows.OpenFile(PChar(userpath+Historydatfile),tmp,0);
//indexfile:=FileOpen(,0);
if indexfile=0 then exit;
FillChar(indexhead,SizeOf(indexhead),#0);
readcount:=FileRead(indexfile,indexhead,SizeOf(indexhead));
indexhead.entryaddr:=ntohs(indexhead.entryaddr);
if (readcount<> SizeOf(indexhead)) or (indexhead.entryaddr=0) then
begin
FileClose(indexfile);
exit;
end;
indexfilesize:=FileSeek(indexfile,0,2);
FileSeek(indexfile,$6000,0);
fileposition:=$6000;
Memo1.Clear;
while True do
begin
fileposition:=FileSeek(indexfile,0,1);
if fileposition+8>=indexfilesize then Break;
keywordFounded:=false;
FillChar(blockhead ,SizeOf(blockhead),#0);
readcount:=FileRead(indexfile,blockhead,SizeOf(blockhead)); //先读8字节的头
blockhead.datasize:=blockhead.datasize*128-sizeof(blockhead);//计算数据段长度
// Move(blockhead.Flags[0],tmpdword,4);
if (readcount<> SizeOf(blockhead)) or (blockhead.datasize=0) then
begin
FileClose(indexfile);
Break;
end;
if (trim(blockhead.Flags)='REDR') then
begin
FileSeek(indexfile,8,1);
blockhead.datasize:=blockhead.datasize-8;
keywordFounded:=true;
end;
if (trim(blockhead.Flags)='URL') then
begin
FileSeek(indexfile,sizeof(TblockUnkown),1);
FileRead(indexfile,quedata,SizeOf(quedata));
blockhead.datasize:=blockhead.datasize-sizeof(quedata)-sizeof(TblockUnkown);
keywordFounded:=true;
end;
if (trim(blockhead.Flags)='LEAK') then
begin
FileRead(indexfile,blockunkwnow,SizeOf(blockunkwnow));
blockhead.datasize:=blockhead.datasize-SizeOf(blockunkwnow);
if blockunkwnow.HaveUrl=$0badf00d then
begin
FileSeek(indexfile,blockhead.datasize,1);
Continue;
end;
FileRead(indexfile,quedata,SizeOf(quedata));
blockhead.datasize:=blockhead.datasize-sizeof(quedata);
keywordFounded:=true;
end;
if not keywordFounded then //如果不是数据块头
begin
FileSeek(indexfile,128-sizeof(blockhead),1);
Continue;
end;
visitetime:='未知日期';
if quedata.visitetime<>0 then
begin
tmpint:=0;
visitetimeh:=ntohs(HiWord(quedata.visitetime));
visitetimel:=ntohs(loword(quedata.visitetime));
Move(visitetimeh,tmpint,2);
tmpint:= tmpint shl 16;
Move(visitetimel,tmpint,2);
tmpint:= ntohl(tmpint);
visitetime:=FormatDateTime('yyyy-mm-dd hh:mm',FileDateToDateTime(tmpint));
end; SetLength(data,0);
SetLength(data,blockhead.datasize);
SetLength(tmpstr,blockhead.datasize);
readcount:=FileRead(indexfile,data[0],blockhead.datasize);
if (readcount<> Length(data)) then
begin
FileClose(indexfile);
Break;
end;
Move(data[0],tmpstr[1],Length(data));
if (tmpstr<>'') and (Pos('.GIF',AnsiUpperCase(tmpstr))<=0)
and (Pos('.JPG',AnsiUpperCase(tmpstr))<=0)
and (Pos('.JS',AnsiUpperCase(tmpstr))<=0)
and (Pos('.CSS',AnsiUpperCase(tmpstr))<=0)
then Memo1.Lines.Add(visitetime+' '+trim(tmpstr));
end;
我在网上找的的方法,但读出后的文件名并不是在windows下看到的名称,而是一个连接地址,为什么?怎么读取文件名称,求高人指点?网上找的方法:
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls,WinSock,StrUtils;
type
TindexdatHead=packed record //index.dat 文件头结构
version:array [0..32]of char;
entryaddr:Word;
unkown:array[0..48] of char;
end;
TblockDataHead=packed record//4字节
Flags:array [0..3]of Char;
datasize:Word;
unknown1:word;
// Visitetime:TDateTime;
end;
TblockUnkown=packed record //76字节
HaveUrl:DWORD;
unknowned:array [0..71]of char;
end;
Tquedata=packed record
unknowned1:DWORD;
unknowned2:DWORD;
visitetime:integer;
unknowned3:array [0..7] of char;
end;type
TForm2 = class(TForm)
Panel1: TPanel;
Button1: TButton;
Label1: TLabel;
Label2: TLabel;
Memo1: TMemo;
Button2: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
function UniCode2GB(S : String):String; public
{ Public declarations }
end;var
Form2: TForm2;implementation{$R *.dfm}procedure TForm2.Button1Click(Sender: TObject);
const Historydatfile='\Local Settings\Temporary Internet Files\Content.IE5\index.dat';// %USERPROFILE%
VAR indexfile:Thandle;
indexhead:TindexdatHead;
readcount:integer;
tmp:_OFSTRUCT;
blockhead:TblockDataHead;
data:array of char;
tmpstr:string;
strFlags:string;
quedata:Tquedata;
blockunkwnow:TblockUnkown;
keywordFounded:boolean;
fileposition:Cardinal;
indexfilesize:Cardinal;
visitetime:string;tmpint:integer;
visitetimeh,visitetimel:word;
userpath:string;
begin
userpath:=GetEnvironmentVariable('USERPROFILE');
indexfile:=windows.OpenFile(PChar(userpath+Historydatfile),tmp,0);
//indexfile:=FileOpen(,0);
if indexfile=0 then exit;
FillChar(indexhead,SizeOf(indexhead),#0);
readcount:=FileRead(indexfile,indexhead,SizeOf(indexhead));
indexhead.entryaddr:=ntohs(indexhead.entryaddr);
if (readcount<> SizeOf(indexhead)) or (indexhead.entryaddr=0) then
begin
FileClose(indexfile);
exit;
end;
indexfilesize:=FileSeek(indexfile,0,2);
FileSeek(indexfile,$6000,0);
fileposition:=$6000;
Memo1.Clear;
while True do
begin
fileposition:=FileSeek(indexfile,0,1);
if fileposition+8>=indexfilesize then Break;
keywordFounded:=false;
FillChar(blockhead ,SizeOf(blockhead),#0);
readcount:=FileRead(indexfile,blockhead,SizeOf(blockhead)); //先读8字节的头
blockhead.datasize:=blockhead.datasize*128-sizeof(blockhead);//计算数据段长度
// Move(blockhead.Flags[0],tmpdword,4);
if (readcount<> SizeOf(blockhead)) or (blockhead.datasize=0) then
begin
FileClose(indexfile);
Break;
end;
if (trim(blockhead.Flags)='REDR') then
begin
FileSeek(indexfile,8,1);
blockhead.datasize:=blockhead.datasize-8;
keywordFounded:=true;
end;
if (trim(blockhead.Flags)='URL') then
begin
FileSeek(indexfile,sizeof(TblockUnkown),1);
FileRead(indexfile,quedata,SizeOf(quedata));
blockhead.datasize:=blockhead.datasize-sizeof(quedata)-sizeof(TblockUnkown);
keywordFounded:=true;
end;
if (trim(blockhead.Flags)='LEAK') then
begin
FileRead(indexfile,blockunkwnow,SizeOf(blockunkwnow));
blockhead.datasize:=blockhead.datasize-SizeOf(blockunkwnow);
if blockunkwnow.HaveUrl=$0badf00d then
begin
FileSeek(indexfile,blockhead.datasize,1);
Continue;
end;
FileRead(indexfile,quedata,SizeOf(quedata));
blockhead.datasize:=blockhead.datasize-sizeof(quedata);
keywordFounded:=true;
end;
if not keywordFounded then //如果不是数据块头
begin
FileSeek(indexfile,128-sizeof(blockhead),1);
Continue;
end;
visitetime:='未知日期';
if quedata.visitetime<>0 then
begin
tmpint:=0;
visitetimeh:=ntohs(HiWord(quedata.visitetime));
visitetimel:=ntohs(loword(quedata.visitetime));
Move(visitetimeh,tmpint,2);
tmpint:= tmpint shl 16;
Move(visitetimel,tmpint,2);
tmpint:= ntohl(tmpint);
visitetime:=FormatDateTime('yyyy-mm-dd hh:mm',FileDateToDateTime(tmpint));
end; SetLength(data,0);
SetLength(data,blockhead.datasize);
SetLength(tmpstr,blockhead.datasize);
readcount:=FileRead(indexfile,data[0],blockhead.datasize);
if (readcount<> Length(data)) then
begin
FileClose(indexfile);
Break;
end;
Move(data[0],tmpstr[1],Length(data));
if (tmpstr<>'') and (Pos('.GIF',AnsiUpperCase(tmpstr))<=0)
and (Pos('.JPG',AnsiUpperCase(tmpstr))<=0)
and (Pos('.JS',AnsiUpperCase(tmpstr))<=0)
and (Pos('.CSS',AnsiUpperCase(tmpstr))<=0)
then Memo1.Lines.Add(visitetime+' '+trim(tmpstr));
end;
解决方案 »
- 【急求】把截屏保存成wmv
- 怎么让打印机打得大一些?
- 誰正確安装过DevExpress Bars 5 ?不够加分
- 如何获得管理员权限啊:在用普通用户(users组)登录2000的时候
- 请交大家一个关于软件字体的问题?
- 通过那些属性来让子窗体显示时,显示在屏幕的某一固定位置,并且能固定它的宽度和高度
- ◆◆◆晕,DELPHI的Undo功能极为不爽◆◆◆谁知道TRW(著名的调试跟踪软件)作者朱南灏开发的那个叫Clip什么来着,是剪贴板工具软件!!!
- 高手请进
- 巨好的FTP站点,有许多许多商业控件!!太全了!!还有许多电子书,俄国人办的,赶快去看。ftp://VCL:[email protected]/
- CoolControls 3.03b的问题
- dbradiogroup
- 请问Delphi中的单元是不是UML中的包,两个单元间的互相引用如何避免?
它里面关联了文件系统下的文件名和url的关联吧。