PeterdeB
asked on
How to mimic this log\feedback behaviour?
Hi my dear friends!
I'm creating this app which empties IE cache. Now I want this app to count files and directories and summarize this along with the amount of MB's of space it occupies, prior to emptying.
Then when emptying it should give feedback about this and afterwards give feedback whether it succeeded.
Now I saw this behaviour in a program I used for creating unattended installs. It also displayed an icon right before every line. Kinda like this:
[icon] [time] Calculating directories: 120 Done!
[icon] [time] Calculating files: 257 Done!
[icon] [time] Calculating space occupied: 200 MB Done!
[icon] [time] Deleting all files and directories....Done!
Something like this.
Regards Paul
Ps thanks in advance, working samples do the trick ofcourse :) This is my code so far. Nothing implemented yet other than the emptying of the cache.
//Code
function TForm1.UserName: String;
var dwSize: DWORD;
begin
// Buffer size to use
dwSize:=256;
// Allocate result buffer
SetLength(result, 256);
// Get user name
if GetUserName(Pointer(result ), dwSize) then
// Truncate to actual result
SetLength(result, Pred(dwSize))
else
// Truncate to null string
SetLength(result, 0);
end;
function DeleteExclude(Path: String; ExcludeFile: String): Boolean;
var lpFileOp: TSHFileOpStruct;
srFind: TSearchRec;
dwFind: Integer;
szPath: String;
szList: String;
begin
// Set default delete list
SetLength(szList, 0);
// Make sure path is correct
szPath:=ExcludeTrailingBac kSlash(Pat h);
// Init the find
dwFind:=FindFirst(szPath+' \*.*', faAnyFile, srFind);
// Check find
if (dwFind = 0) then
begin
// Resource protection
try
// While sucess
while (dwFind = 0) do
begin
// Check name
if ((Length(srFind.Name) > 0) and not(srFind.Name[1] = '.')) then
begin
// Compare against exclusion
if (CompareText(srFind.Name, ExtractFileName(ExcludeFil e)) <> 0) then
begin
// Add to list
szList:=szList+szPath+'\'+ srFind.Nam e+#0;
end;
end;
// Find next
dwFind:=FindNext(srFind);
end;
finally
// Close the find
FindClose(srFind);
end;
end;
// Check the list
if (Length(szList) > 0) then
begin
// Double null terminate the list
szList:=szList+#0;
// Clear struct
FillChar(lpFileOp, SizeOf(lpFileOp), 0);
// Set params
lpFileOp.Wnd:=Application. Handle;
lpFileOp.wFunc:=FO_DELETE;
lpFileOp.pFrom:=PChar(szLi st);
lpFileOp.pTo:=nil;
// Remove the FOF_ALLOWUNDO if you don't want this to go in the recycle bin
lpFileOp.fFlags:=FOF_SILEN T or FOF_NOCONFIRMATION or FOF_ALLOWUNDO;
// Perform the delete
if (SHFileOperation(lpFileOp) = 0) and (lpFileOp.fAnyOperationsAb orted = False) then
// Success
result:=True
else
// Failure
result:=False;
end
else
// Nothing to delete
result:=True;
end;
procedure TForm1.Btn1Click(Sender: TObject);
begin
if DeleteExclude('c:\document s and settings\'+UserName+'\loca l settings\temporary internet files\content.ie5', 'index.dat') then
ShowMessage('Success')
else
ShowMessage('Failure');
end;
end.
// End of code
Tnx to esoftbg, inthe and rlibby for the above piece of code!
I'm creating this app which empties IE cache. Now I want this app to count files and directories and summarize this along with the amount of MB's of space it occupies, prior to emptying.
Then when emptying it should give feedback about this and afterwards give feedback whether it succeeded.
Now I saw this behaviour in a program I used for creating unattended installs. It also displayed an icon right before every line. Kinda like this:
[icon] [time] Calculating directories: 120 Done!
[icon] [time] Calculating files: 257 Done!
[icon] [time] Calculating space occupied: 200 MB Done!
[icon] [time] Deleting all files and directories....Done!
Something like this.
Regards Paul
Ps thanks in advance, working samples do the trick ofcourse :) This is my code so far. Nothing implemented yet other than the emptying of the cache.
//Code
function TForm1.UserName: String;
var dwSize: DWORD;
begin
// Buffer size to use
dwSize:=256;
// Allocate result buffer
SetLength(result, 256);
// Get user name
if GetUserName(Pointer(result
// Truncate to actual result
SetLength(result, Pred(dwSize))
else
// Truncate to null string
SetLength(result, 0);
end;
function DeleteExclude(Path: String; ExcludeFile: String): Boolean;
var lpFileOp: TSHFileOpStruct;
srFind: TSearchRec;
dwFind: Integer;
szPath: String;
szList: String;
begin
// Set default delete list
SetLength(szList, 0);
// Make sure path is correct
szPath:=ExcludeTrailingBac
// Init the find
dwFind:=FindFirst(szPath+'
// Check find
if (dwFind = 0) then
begin
// Resource protection
try
// While sucess
while (dwFind = 0) do
begin
// Check name
if ((Length(srFind.Name) > 0) and not(srFind.Name[1] = '.')) then
begin
// Compare against exclusion
if (CompareText(srFind.Name, ExtractFileName(ExcludeFil
begin
// Add to list
szList:=szList+szPath+'\'+
end;
end;
// Find next
dwFind:=FindNext(srFind);
end;
finally
// Close the find
FindClose(srFind);
end;
end;
// Check the list
if (Length(szList) > 0) then
begin
// Double null terminate the list
szList:=szList+#0;
// Clear struct
FillChar(lpFileOp, SizeOf(lpFileOp), 0);
// Set params
lpFileOp.Wnd:=Application.
lpFileOp.wFunc:=FO_DELETE;
lpFileOp.pFrom:=PChar(szLi
lpFileOp.pTo:=nil;
// Remove the FOF_ALLOWUNDO if you don't want this to go in the recycle bin
lpFileOp.fFlags:=FOF_SILEN
// Perform the delete
if (SHFileOperation(lpFileOp)
// Success
result:=True
else
// Failure
result:=False;
end
else
// Nothing to delete
result:=True;
end;
procedure TForm1.Btn1Click(Sender: TObject);
begin
if DeleteExclude('c:\document
ShowMessage('Success')
else
ShowMessage('Failure');
end;
end.
// End of code
Tnx to esoftbg, inthe and rlibby for the above piece of code!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
No problem ;-), and enjoy your weekend
Russell
Russell
ASKER
Many thanks Russel!!
Regards Paul :)