SRL Archive - SRL Archives

FileExists() function returns true if the file exists.


Ron

2007-01-06 23:24:51

Returns true if the file exists. :)

Function code:

// FileExists() will check if a file exists on your computer.
// Made by Ron. :)
function FileExists(Location: string): Boolean;
var
a: TStringList;
begin
try
a := TStringList.Create;
a.LoadFromFile(Location);
finally
a.free;
Result := True;
except
Result := False;
end;
end;

Test Function Code:

program New;

const
TheFile = 'c:\Windows\regedit.exe';

// FileExists() will check if a file exists on your computer.
// Made by Ron. :)
function FileExists(Location: string): Boolean;
var
a: TStringList;
begin
try
a := TStringList.Create;
a.LoadFromFile(Location);
finally
a.free;
Result := True;
except
Result := False;
end;
end;

begin
ClearDebug;
if(FileExists(TheFile))then
WriteLn(TheFile + ' exists!')
else
WriteLn(TheFile + ' does not exist!');
end.

~Ron

WhiteShadow

2007-01-06 23:58:04

Nice simple function, can be very useful. ;]

Ron

2007-01-07 00:15:46

I spoke about the usefulness of this function to cheesehunk over MSN.

Do you think it's a good idea for SRL to check if all the files exists, especially the ones that exist in the plugins folder? Cheesehunk said no cause SRL automatically puts it in there, but idk people still post saying they get errors and people tell them to put the plugins in the proper folder, they do that, and it works.

So do whatever, I just hope it helps in some way. :)

Cheesehunk

2007-01-07 02:20:32

From: Ron

Do you think it's a good idea for SRL to check if all the files exists, especially the ones that exist in the plugins folder? Cheesehunk said no cause SRL automatically puts it in there, but idk people still post saying they get errors and people tell them to put the plugins in the proper folder, they do that, and it works.

Most of the problems are from when you download it with SCAR open, then attempt to run it right away. A couple times I have accidentally done this with my SVN before moving the Plugins. I then go to question Freddy, and realize my foolish mistake. Closing all SCAR's, and trying again should fix the error.

I do like the function though. :)

WhiteShadow

2007-01-07 03:11:12

woops double post.

WhiteShadow

2007-01-07 03:20:57

From: Ron
I spoke about the usefulness of this function to cheesehunk over MSN.

Do you think it's a good idea for SRL to check if all the files exists, especially the ones that exist in the plugins folder? Cheesehunk said no cause SRL automatically puts it in there, but idk people still post saying they get errors and people tell them to put the plugins in the proper folder, they do that, and it works.

So do whatever, I just hope it helps in some way. :)


Well maybe a separate SRL file, that noobies specifically run if they're getting errors that deal with not having certain files. (: That's a good idea. SRL doesn't automatically put it there, it just comes with the rar package. I guess some people don't know how to extract correctly? :confused:

I'd probably just use it in my own script though.

procedure NoobScanner;
var
iFile : String;
begin
iFile:= AppPath +'Plugins\BoxPlugin.dll';
if(not(FileExists(iFile)))then
begin
Writeln(iFile);
Writeln('O dang your a noob!');
TerminateScript;
end;
end;