Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[Delphi]Searching through LocalDisk for a File ?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
DeletedUser14087
I post too much
Reputation: 2

Joined: 21 Jun 2006
Posts: 3069

PostPosted: Tue Apr 08, 2008 10:03 am    Post subject: [Delphi]Searching through LocalDisk for a File ? Reply with quote

my stupid code is:
Code:
function ScanFolder(filename:string;dir:string):boolean;
var Data:TWin32FindDataA;
    fsearch:thandle;
    t:BOOL;
    lol:boolean;
begin
fsearch:=FindFirstFile(pchar(filename) and pchar(dir),Data);
if fsearch <> INVALID_HANDLE_VALUE then lol := false;

 while lol = False do
  begin
  t:=FindNextFile(fsearch,Data);
  Sleep(10);
  if t = true then lol:=true;
  end;
Result:=False;
end;


useage:

Code:
if ScanFolder('Somefile.exe,'C:\') = True then ShowMessage('yes')
else showmessage('no');


help would be appreaciated
Back to top
View user's profile Send private message
HolyBlah
Master Cheater
Reputation: 2

Joined: 24 Aug 2007
Posts: 446

PostPosted: Tue Apr 08, 2008 11:16 am    Post subject: Reply with quote

Try to use FileExists, else use this:
Code:
function ScanFolder(filename:string;dir:string):boolean;
var
   Data:TWin32FindDataA;
    fsearch:thandle;
begin
   result:=false;
   fsearch:=FindFirstFile(pchar(dir + filename),Data);
   if fsearch <> INVALID_HANDLE_VALUE then
      repeat
      Sleep(10);
      result:=true;
      until FindNextFile(fsearch,Data) = 0;
   FindClose(fsearch);
end;
Back to top
View user's profile Send private message
DeletedUser14087
I post too much
Reputation: 2

Joined: 21 Jun 2006
Posts: 3069

PostPosted: Tue Apr 08, 2008 12:23 pm    Post subject: Reply with quote

HolyBlah wrote:
Try to use FileExists, else use this:
Code:
function ScanFolder(filename:string;dir:string):boolean;
var
   Data:TWin32FindDataA;
    fsearch:thandle;
begin
   result:=false;
   fsearch:=FindFirstFile(pchar(dir + filename),Data);
   if fsearch <> INVALID_HANDLE_VALUE then
      repeat
      Sleep(10);
      result:=true;
      until FindNextFile(fsearch,Data) = 0;
   FindClose(fsearch);
end;


HolyBlah, FileExists needs full path, also your code has error

until FindNextFile(fsearch,Data) = 0; should be:

until FindNextFile(fsearch,Data) = True;

and findclose is targeted to Sysutils, so do:

Windows.FindClose();

also, your code doesn't work well S:, no return value AT ALL, nothing happens
Back to top
View user's profile Send private message
HolyBlah
Master Cheater
Reputation: 2

Joined: 24 Aug 2007
Posts: 446

PostPosted: Wed Apr 09, 2008 7:19 am    Post subject: Reply with quote

So here it is again:
Code:
function ScanFolder(filename:string;dir:string):boolean;
var
   Data:TWin32FindDataA;
    fsearch:THandle;
begin
  result:=false;
  fsearch:=(FindFirstFile(pchar(dir + filename),Data));
  if fsearch <> -1 then
    result:=true;
    Windows.FindClose(fsearch);
end;

Btw: You don't have to compare boolean to true/false.
Back to top
View user's profile Send private message
Hixk is my hero
Grandmaster Cheater
Reputation: 0

Joined: 22 Sep 2007
Posts: 611

PostPosted: Wed Apr 09, 2008 4:57 pm    Post subject: Reply with quote

Is this the sort of thing you wanted?

Code:
function ScanFolder(FileName:String; Directory:String):Boolean;
var
  FileFound: TSearchRec;
begin
  if FindFirst(Directory + FileName, faAnyFile, FileFound) = 0 then begin
    Result := True;
    FindClose(FileFound);
  end else begin
    Result := False;
    FindClose(FileFound);
  end;
end;


And as HolyBlah said, you don't have to compare to True / False, so usage would be:

Code:
procedure TForm1.Button1Click(Sender: TObject);
begin
  if ScanFolder('WINDOWS','C:\') then begin // Note the lack of = True
    ShowMessage('WINDOWS was found in C:\');
  end else begin
    ShowMessage('WINDOWS was not found in C:\');
  end;
end;

_________________
I'm LolSalad.
Back to top
View user's profile Send private message
DeletedUser14087
I post too much
Reputation: 2

Joined: 21 Jun 2006
Posts: 3069

PostPosted: Fri Apr 11, 2008 9:49 am    Post subject: Reply with quote

Hixk is my hero wrote:
Is this the sort of thing you wanted?

Code:
function ScanFolder(FileName:String; Directory:String):Boolean;
var
  FileFound: TSearchRec;
begin
  if FindFirst(Directory + FileName, faAnyFile, FileFound) = 0 then begin
    Result := True;
    FindClose(FileFound);
  end else begin
    Result := False;
    FindClose(FileFound);
  end;
end;


And as HolyBlah said, you don't have to compare to True / False, so usage would be:

Code:
procedure TForm1.Button1Click(Sender: TObject);
begin
  if ScanFolder('WINDOWS','C:\') then begin // Note the lack of = True
    ShowMessage('WINDOWS was found in C:\');
  end else begin
    ShowMessage('WINDOWS was not found in C:\');
  end;
end;


FFS i know you don't need to use the = True/False, but boolean is for True/False only (the function must return a value), unless HolyBlah will use BOOL
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites