SRL Archive - Research & Development Lounge

[FUNCTION WORKS!!] DeleteFile


Da 0wner

2008-10-22 08:58:06


{*******************************************************************************
function DeleteFile(Path : string) : boolean;
By: Da 0wner
Description: Deletes the file specified by the path variable.
*******************************************************************************}
function DeleteFile(Path : string) : boolean;
var
FileNum : integer;
begin
if not FileExists(Path) then exit;
FileNum := RewriteFile(AppPath + 'Includes\SRL\SRL\Misc\DeleteFile.bat', true);
WriteFileString(FileNum, 'del ' + Path);
writeln(AppPath + 'Includes\SRL\SRL\Misc\DeleteFile.bat');
CloseFile(FileNum);
OpenWebPage(AppPath + 'Includes\SRL\SRL\Misc\DeleteFile.bat');
if not FileExists(Path) then Result := True;
end;

Returns true if the file was deleted. Please don't edit the procedure if you decide to use it. I thought of it :).

Rep me if you like it!!

The Un-Named

2008-10-22 10:36:09

I voted "no", simply because of the abuse factor, and a plugin for more advanced file reading/writing/creating/deleting etc would be faster/better and possibly safer with certain permissions.

Shuttleu

2008-10-22 10:50:18

it didnt work so i vote no

~shut

Da 0wner

2008-10-22 11:05:26

Hmm shut show me the script you were trying to run and verify that you had a file there.

You should run this replacing C:\YourFile.ext with the PATH and filename (i.e 'C:\File.txt') file you want to delete.


Program New;

{*******************************************************************************
function DeleteFile(Path : string) : boolean;
By: Da 0wner
Description: Deletes the file specified by the path variable.
Please do not edit the procedure.
*******************************************************************************}
function DeleteFile(Path : string) : boolean;
var
FileNum : integer;
begin
if not FileExists(Path) then exit;
FileNum := RewriteFile(AppPath + 'Includes\SRL\SRL\Misc\DeleteFile.bat', true);
WriteFileString(FileNum, 'del ' + Path);
CloseFile(FileNum);
OpenWebPage(AppPath + 'Includes\SRL\SRL\Misc\DeleteFile.bat');
Wait(1000);
if not FileExists(Path) then Result := True;
end;

begin
if DeleteFile('C:\YourFile.ext') then
begin
Writeln('It succeeded!');
TerminateScript;
end;
Writeln('It didn''t work :(');
end.

Shuttleu

2008-10-22 12:25:42

this is what i used
program New;
function DeleteFile(Path : string) : boolean;
var
FileNum : integer;
begin
if not FileExists(Path) then exit;
FileNum := RewriteFile(AppPath + 'Includes\SRL\SRL\Misc\DeleteFile.bat', true);
WriteFileString(FileNum, 'del ' + Path);
writeln(AppPath + 'Includes\SRL\SRL\Misc\DeleteFile.bat');
CloseFile(FileNum);
OpenWebPage(AppPath + 'Includes\SRL\SRL\Misc\DeleteFile.bat');
if not FileExists(Path) then Result := True;
end;
begin
DeleteFile('C:\NewTextDocument.txt');
end.
and it works now but what use would you have by deleting some files?
it would be faster to go to the directory yourself and delete it that way

~shut

Dan Cardin

2008-10-22 14:20:35

hmm thats odd, there isnt a deletefile procedure :(, and i would vote no because it uses a seperate file.

bullzeye95

2008-10-22 14:34:38

function DeleteFile(const lpFileName: String): Boolean; external 'DeleteFileA@kernel32.dll stdcall';

MylesMadness

2008-10-22 15:15:44

From: bullzeye95
function DeleteFile(const lpFileName: String): Boolean; external 'DeleteFileA@kernel32.dll stdcall';
API call though

NiCbaZ

2008-10-22 16:47:03

SSince you wont et us edit it, no.

bullzeye95

2008-10-22 17:08:26

From: Mylesmadness
API call though


I found it better to simply delete a file than to create a file to delete a file though.

MylesMadness

2008-10-22 17:44:52

From: bullzeye95
I found it better to simply delete a file than to create a file to delete a file though.
Not every person has api calls always enabled.

Da 0wner

2008-10-22 17:45:30

It uses the same file over and over so you only create it once. And that is the only solution without plugins/API calls.

Dan Cardin

2008-10-22 18:08:19

unless freddy happens to see this thread and add the function, knowing that the fate of his reputation as a coder now lays on the addition of this single function.