Re: file delete routine is intermittent
- From: "MikeD" <nobody@xxxxxxxxxxx>
- Date: Wed, 20 Apr 2005 10:33:14 -0400
"Jonathan Wood" <jwood@xxxxxxxxxxxxxxxx> wrote in message
news:u574SeSRFHA.2736@xxxxxxxxxxxxxxxxxxxxxxx
> Mike,
>
> > Try this:
> >
> > .pFrom = file2delete & vbNullChar & vbNullChar 'the file to delete
>
> This is not necessary as Visual Basic automatically appends a single null
> terminator character to every string.
Only when you pass a string as a parameter (and pass it ByVal). In this
case, you're passing a structure. VB does NOT automatically append a null
character to string members of structures so you must append the null
character yourself. I'm very surprised you weren't aware of that.
> I wondered about the double terminator at the end, that could be a
problem.
> However, if SHFileOperation didn't find a double terminator, it would
> attempt to delete additional filenames and wouldn't skip filenames as the
OP
> complained about.
Not necessarily. UnderWin95/98, the function works fine if you don't append
a null character at all (let alone 2). This has nothing to do with VB. It
has everything to do with Win95/98 not being as strict for some API
functions. Under any NT-based version of Windows, the function is
considerably stricter and if you don't have the double null-termination, the
function is unpredictable. It may not delete any files, it may delete a
wrong file, it may delete multiple files (for the FO_DELETE action). At
least, this has been my experience.
>
> > pFrom
> > Address of a buffer to specify one or more source file names. These
names
> > must be fully qualified paths. Standard DOS wild cards, such as "*", are
> > permitted in the filename position. Although this member is declared as
a
> > null-terminated string, it is used as a buffer to hold multiple file
> names.
> > Each file name must be terminated by a single NULL character. An
> additional
> > NULL character must be appended to the end of the final name to indicate
> the
> > end of pFrom.
>
> Sounds like his best bet is to simply pass the wildcard specification to
> SHFileOperation instead of locating matching filenames himself. He may
also
> want to use my wrapper class as that deals with some other potential
> problems.
In this particular case, probably. That'd also eliminate having to use
FindFirstFile, etc. and the loop.
--
Mike
Microsoft MVP Visual Basic
.
- Follow-Ups:
- Re: file delete routine is intermittent
- From: Jonathan Wood
- Re: file delete routine is intermittent
- References:
- file delete routine is intermittent
- From: Steve Easton
- Re: file delete routine is intermittent
- From: MikeD
- Re: file delete routine is intermittent
- From: Jonathan Wood
- file delete routine is intermittent
- Prev by Date: Re: SendMessage vs. SendKeys
- Next by Date: Re: SendMessage vs. SendKeys
- Previous by thread: Re: file delete routine is intermittent
- Next by thread: Re: file delete routine is intermittent
- Index(es):
Relevant Pages
|
Loading