🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #11045

Re: FindFirstFile, FindNext Problem

#11045
From: Remy Lebeau (TeamB)
Date: Mon, 01 Mar 2004 07:36
63 lines
3561 bytes
"Martin C" <martinc@aol.com> wrote in message
news:4042c611@newsgroups.borland.com...

> As long as I use DeleteFile function there is no problem at all, all
> files are deleted fast. But when I add some functions to securely
> overwrite and delete files so it can't be recovered, I find that the
> DeleteAllFilesFolders function delete some files and leave other,
> without any logical reason why those files where left

My guess would be that your secure deletion functions are not closing all
file handles correctly, and/or not allowing files to be fully closed and
flushed to disk adequately before then trying to delete them, such that
DeleteFile() is then failing afterwards.

>   hFind = FindFirstFile((LPCTSTR)FileInformation.c_str(), &FindFileData);

Why are you calling FindFirstFile() again?  You already have all of the
relavant file information available for the given file before you call
SecureDeleteFiles() (btw, why is the function name plural if you are only
deleting a single file?).

>      SecureDelete1(FileName.c_str(), FindFileData.nFileSizeHigh,
> FindFileData.nFileSizeLow);

Where is FileName declared and where does it get its value from?  Again, you
are showing bits of pieces of incomplete code that suggest you are not
copy/pasting your actual code as-is directly from your project.  If you are,
in fact, copy/pasting your code directly, then you have a bug in your code
in that you are not using the function's FileInformation parameter when
calling SecureDelete1().

Since you are calling SecureDeleteFiles() for the sole purpose of calling
FindFirstFile() to obtain data you already have anyway, you can get rid of
SecureDeleteFiles() altogether and call SecureDelete1() from
DeleteAllFilesFolders() directly:

    if( MatchesMask(wfd.cFileName, MaskToFind) )
    {
        if( SecureDeleteOn )
            Result = ::DeleteFile(sFullPath.c_str());
        else
            Result = SecureDelete1(sFullPath.c_str(), wfd.nFileSizeHigh,
wfd.nFileSizeLow);
    }

BTW, shouldn't that if() statement be the other way around?  Naming a
variable 'SecureDeleteOn' suggests that you want secure deleting when the
value is 'true', but you did not actually code it that way.

>   SetFilePointer( hFile, FileLengthLo, (PLONG)&FileLengthHi, FILE_BEGIN);

If all you are trying to do is seek to the end of the file, you could use
FILE_END instead:

    SetFilePointer( hFile, -1, NULL, FILE_END );

> CloseHandle( hFile );

Try calling FlushFileBuffers() before closing the file handle.


Gambit
Technical Details
Message-ID: <4042e5f3@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <4042b3bc@newsgroups.borland.com> <4042b964$1@newsgroups.borland.com> <4042c611@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,cd3253abe6cdd94c
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2004-02-29 23:39:29 PST
From: "Remy Lebeau \(TeamB\)" <gambit47.no.spam@no.spam.yahoo.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <4042b3bc@newsgroups.borland.com> <4042b964$1@newsgroups.borland.com> <4042c611@newsgroups.borland.com>
Subject: Re: FindFirstFile, FindNext Problem
Date: Sun, 29 Feb 2004 23:36:14 -0800
Lines: 65
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
NNTP-Posting-Host: 67.22.138.253
Message-ID: <4042e5f3@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1078126067 67.22.138.253 (29 Feb 2004 23:27:47 -0800)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail