Re: file delete routine is intermittent




"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


.



Relevant Pages

  • Re: file delete routine is intermittent
    ... >> terminator character to every string. ... > Only when you pass a string as a parameter. ... VB does NOT automatically append a null ...
    (microsoft.public.vb.winapi)
  • Re: file delete routine is intermittent
    ... >>> terminator character to every string. ... >> Only when you pass a string as a parameter. ... >> character to string members of structures so you must append the null ...
    (microsoft.public.vb.winapi)
  • Re: Unicode: ugh!
    ... a string is defined as a pointer to char in the ... by and including the first null character. ... the null terminator is not a NULL character (NULL ...
    (comp.lang.c)
  • Re: file delete routine is intermittent
    ... terminator character to every string. ... I wondered about the double terminator at the end, ... attempt to delete additional filenames and wouldn't skip filenames as the OP ... > Each file name must be terminated by a single NULL character. ...
    (microsoft.public.vb.winapi)
  • [TOMOYO #15 3/8] Common functions for TOMOYO Linux.
    ... This file contains common functions (e.g. policy I/O, pattern matching). ... Since TOMOYO Linux is a name based access control, ... TOMOYO Linux's string manipulation functions make reviewers feel crazy, ... the Linux kernel accepts all characters but NUL character ...
    (Linux-Kernel)

Loading