Hi all,

I would like to delete from a directory all the files that match: bar*.*
I know that I could do for instance: system("del bar*.*"), but this will
bring up the command prompt window and as my app is a winmain app this
wouldn't be nice. I could use DeleteFile, but you can not use wildcards
in this one.

How could I do this using Windows functions?

Thanks in advance,
Viv

Re: Delete all files with "a pattern" by El

El
Wed May 12 10:59:22 CDT 2004

Hello,

You can either use "SHFileOperation" with FO_DELETE flag set in the
SHFILEOPSTRUCT structure or browse the directory deleting files that match
your expression using "PathMatchSpec" function.

Regards,
Arno

"Viviana Vc" <vcotirlea@hotmail.com> a écrit dans le message de
news:2gevilF1sfksU1@uni-berlin.de...
> Hi all,
>
> I would like to delete from a directory all the files that match: bar*.*
> I know that I could do for instance: system("del bar*.*"), but this will
> bring up the command prompt window and as my app is a winmain app this
> wouldn't be nice. I could use DeleteFile, but you can not use wildcards
> in this one.
>
> How could I do this using Windows functions?
>
> Thanks in advance,
> Viv



Re: Delete all files with "a pattern" by AlexS

AlexS
Wed May 12 14:08:38 CDT 2004

Hi, Viviana

Have a look at Directory.GetFiles method. You can get list of files using
mask and then delete them using standard File.Delete method.

HTH
Alex

"Viviana Vc" <vcotirlea@hotmail.com> wrote in message
news:2gevilF1sfksU1@uni-berlin.de...
> Hi all,
>
> I would like to delete from a directory all the files that match: bar*.*
> I know that I could do for instance: system("del bar*.*"), but this will
> bring up the command prompt window and as my app is a winmain app this
> wouldn't be nice. I could use DeleteFile, but you can not use wildcards
> in this one.
>
> How could I do this using Windows functions?
>
> Thanks in advance,
> Viv



Re: Delete all files with "a pattern" by Sten

Sten
Thu May 13 12:10:03 CDT 2004


"Viviana Vc" <vcotirlea@hotmail.com> wrote in message
news:2gevilF1sfksU1@uni-berlin.de...
> Hi all,
>
> I would like to delete from a directory all the files that match: bar*.*
> I know that I could do for instance: system("del bar*.*"), but this will
> bring up the command prompt window and as my app is a winmain app this
> wouldn't be nice. I could use DeleteFile, but you can not use wildcards
> in this one.
>
> How could I do this using Windows functions?

Use FindFirstFile() and it's siblings to get the file names and then
DeleteFile().

- Sten




Re: Delete all files with "a pattern" by Viviana

Viviana
Thu May 13 12:18:49 CDT 2004

Thanks for the answer. I have tried using SHFileOperation and it works,
but I still have a problem.

I want to delete the files named: file.log.1, file.log.2, ...,
file.log.x, _but_ not to delete: file.log

If I use "file.log.*" in pFrom, also the file.log will be deleted. How
can I avoid this?

Thx in advance,
Viv

On Wed, 12 May 2004 17:59:22 +0200, "El Cascador !!!"
<no.elcascador@free.fr.spam> wrote :

>Hello,
>
>You can either use "SHFileOperation" with FO_DELETE flag set in the
>SHFILEOPSTRUCT structure or browse the directory deleting files that match
>your expression using "PathMatchSpec" function.
>
>Regards,
>Arno
>
>"Viviana Vc" <vcotirlea@hotmail.com> a écrit dans le message de
>news:2gevilF1sfksU1@uni-berlin.de...
>> Hi all,
>>
>> I would like to delete from a directory all the files that match: bar*.*
>> I know that I could do for instance: system("del bar*.*"), but this will
>> bring up the command prompt window and as my app is a winmain app this
>> wouldn't be nice. I could use DeleteFile, but you can not use wildcards
>> in this one.
>>
>> How could I do this using Windows functions?
>>
>> Thanks in advance,
>> Viv
>


Re: Delete all files with "a pattern" by Sten

Sten
Fri May 14 07:01:21 CDT 2004


Method 1: Enumerate the files yourself and detect when you shouldn't delete.
Method 2: Temporarily add ReadOnly-attribute or lock the file that shouldn't
be deleted.

- Sten

"Viviana Vc" <vcotirlea@hotmail.com> wrote in message
news:2ghosnF3298qU1@uni-berlin.de...
> Thanks for the answer. I have tried using SHFileOperation and it works,
> but I still have a problem.
>
> I want to delete the files named: file.log.1, file.log.2, ...,
> file.log.x, _but_ not to delete: file.log
>
> If I use "file.log.*" in pFrom, also the file.log will be deleted. How
> can I avoid this?
>
> Thx in advance,
> Viv
>
> On Wed, 12 May 2004 17:59:22 +0200, "El Cascador !!!"
> <no.elcascador@free.fr.spam> wrote :
>
> >Hello,
> >
> >You can either use "SHFileOperation" with FO_DELETE flag set in the
> >SHFILEOPSTRUCT structure or browse the directory deleting files that
match
> >your expression using "PathMatchSpec" function.
> >
> >Regards,
> >Arno
> >
> >"Viviana Vc" <vcotirlea@hotmail.com> a écrit dans le message de
> >news:2gevilF1sfksU1@uni-berlin.de...
> >> Hi all,
> >>
> >> I would like to delete from a directory all the files that match:
bar*.*
> >> I know that I could do for instance: system("del bar*.*"), but this
will
> >> bring up the command prompt window and as my app is a winmain app this
> >> wouldn't be nice. I could use DeleteFile, but you can not use wildcards
> >> in this one.
> >>
> >> How could I do this using Windows functions?
> >>
> >> Thanks in advance,
> >> Viv
> >
>



Re: Delete all files with "a pattern" by El

El
Fri May 14 10:14:10 CDT 2004

Are you sure it will delete file.log ?
It shouldn't, there is no point after the filename...
Anyway, you may want to use generic character '?' that can replace ONE
character...
... and try "file.log.?"...

Regards,
Arno

"Viviana Vc" <vcotirlea@hotmail.com> a écrit dans le message de
news:2ghosnF3298qU1@uni-berlin.de...
> Thanks for the answer. I have tried using SHFileOperation and it works,
> but I still have a problem.
>
> I want to delete the files named: file.log.1, file.log.2, ...,
> file.log.x, _but_ not to delete: file.log
>
> If I use "file.log.*" in pFrom, also the file.log will be deleted. How
> can I avoid this?
>
> Thx in advance,
> Viv
>
> On Wed, 12 May 2004 17:59:22 +0200, "El Cascador !!!"
> <no.elcascador@free.fr.spam> wrote :
>
> >Hello,
> >
> >You can either use "SHFileOperation" with FO_DELETE flag set in the
> >SHFILEOPSTRUCT structure or browse the directory deleting files that
match
> >your expression using "PathMatchSpec" function.
> >
> >Regards,
> >Arno
> >
> >"Viviana Vc" <vcotirlea@hotmail.com> a écrit dans le message de
> >news:2gevilF1sfksU1@uni-berlin.de...
> >> Hi all,
> >>
> >> I would like to delete from a directory all the files that match:
bar*.*
> >> I know that I could do for instance: system("del bar*.*"), but this
will
> >> bring up the command prompt window and as my app is a winmain app this
> >> wouldn't be nice. I could use DeleteFile, but you can not use wildcards
> >> in this one.
> >>
> >> How could I do this using Windows functions?
> >>
> >> Thanks in advance,
> >> Viv
> >
>



Re: Delete all files with "a pattern" by Andreas

Andreas
Wed May 12 14:07:07 CDT 2004

Viviana Vc <vcotirlea@hotmail.com> wrote:

>Hi all,
>
>I would like to delete from a directory all the files that match: bar*.*
>I know that I could do for instance: system("del bar*.*"), but this will
>bring up the command prompt window and as my app is a winmain app this
>wouldn't be nice. I could use DeleteFile, but you can not use wildcards
>in this one.
>

STARTUPINFO si;
PROCESS_INFORMATION pi;

ZeroMemory( &si, sizeof(si) );
si.dwFlags |= STARTF_USESHOWWINDOW ;
si.wShowWindow = SW_HIDE ;
si.cb = sizeof(si);

ZeroMemory( &pi, sizeof(pi) );

if ( CreateProcess( NULL, // Name of Application
"del bar*.*", // command line
NULL, // process attributes
NULL, // Thread attributes
FALSE, // no inheritable handle
0, // Creation flags
NULL, // use callers environment
NULL, // use current directory
&si,
&pi
)
)
{
DWORD dwExitCode = 1 ; // preset: error
DWORD dwWaitResult ;
dwWaitResult = WaitForSingleObject( pi.hProcess, INFINITE ) ;
if ( WAIT_OBJECT_0 == dwWaitResult
&& GetExitCodeProcess( pi.hProcess, &dwExitCode )
&& 0 == dwExitCode
)
{
// success
}
else
{
// failed
}
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
}
else
{
// failed
}

Andreas
--
If C++ has taught me one thing, it's this: Just because the system is
consistent doesn't mean it's not the work of Satan.
-- Andrew Plotkin

Re: Delete all files with "a pattern" by Andreas

Andreas
Thu May 13 15:16:10 CDT 2004

Viviana Vc <vcotirlea@hotmail.com> wrote:

>Thanks for the answer. I have tried using SHFileOperation and it works,
>but I still have a problem.
>
>I want to delete the files named: file.log.1, file.log.2, ...,
>file.log.x, _but_ not to delete: file.log
>
>If I use "file.log.*" in pFrom, also the file.log will be deleted. How
>can I avoid this?

In cmd, I regularily do

ren yyy.log xxx
del yyy.*
ren xxx yyy.log

Andreas
--
Every program has at least one bug and can be reduced by at least one
line. By induction, then, every program can be reduced to a single
instruction, and that will be wrong.
(unknown)

Re: Delete all files with "a pattern" by Sten

Sten
Mon May 24 04:11:16 CDT 2004


"Andreas Hadler" <Andreas.Hadler@t-online.de> wrote in message
news:27t4a0tvrumn8ug5rte5lbmnu45jvqefvr@4ax.com...
> Viviana Vc <vcotirlea@hotmail.com> wrote:
>
> >Hi all,
> >
> >I would like to delete from a directory all the files that match: bar*.*
> >I know that I could do for instance: system("del bar*.*"), but this will
> >bring up the command prompt window and as my app is a winmain app this
> >wouldn't be nice. I could use DeleteFile, but you can not use wildcards
> >in this one.
> >
>
> STARTUPINFO si;
> PROCESS_INFORMATION pi;
>
> ZeroMemory( &si, sizeof(si) );
> si.dwFlags |= STARTF_USESHOWWINDOW ;
> si.wShowWindow = SW_HIDE ;
> si.cb = sizeof(si);
>
> ZeroMemory( &pi, sizeof(pi) );
>
> if ( CreateProcess( NULL, // Name of Application
> "del bar*.*", // command line
> NULL, // process attributes
> NULL, // Thread attributes
> FALSE, // no inheritable handle
> 0, // Creation flags
> NULL, // use callers environment
> NULL, // use current directory
> &si,
> &pi
> )
> )
> {
> DWORD dwExitCode = 1 ; // preset: error
> DWORD dwWaitResult ;
> dwWaitResult = WaitForSingleObject( pi.hProcess, INFINITE ) ;
> if ( WAIT_OBJECT_0 == dwWaitResult
> && GetExitCodeProcess( pi.hProcess, &dwExitCode )
> && 0 == dwExitCode
> )
> {
> // success
> }
> else
> {
> // failed
> }
> CloseHandle( pi.hProcess );
> CloseHandle( pi.hThread );
> }
> else
> {
> // failed
> }
>
> Andreas

Did you test that? I would claim that you have to inform shellexecute that
the REN command is inside CMD.exe .. that is "cmd /c ren .....". Also,
i can't see why ShellExecute() couldn't be used as well.

- Sten




Re: Delete all files with "a pattern" by Jussi

Jussi
Tue May 25 04:51:43 CDT 2004

Viviana Vc wrote:

> I would like to delete from a directory all the files that match:
> bar*.* I know that I could do for instance: system("del bar*.*"),
> but this will bring up the command prompt window and as my app is
> a winmain app this wouldn't be nice. I could use DeleteFile, but
> you can not use wildcards in this one.
>
> How could I do this using Windows functions?

Use CreateProcess and set the show flag to SW_HIDE.

Jussi Jumppanen
Author of: Zeus for Windows, Win32 (Brief, Emacs, etc) FTP Text Editor
"The C/C++, Java, HTML, FTP, Python, PHP, Perl programmer's editor"
Home Page: http://www.zeusedit.com

Re: Delete all files with "a pattern" by Andreas

Andreas
Mon May 24 13:51:26 CDT 2004

"Sten Westerback" <sten.westerback@NO_SPAMnokia.com> wrote:

>
>"Andreas Hadler" <Andreas.Hadler@t-online.de> wrote in message
>news:27t4a0tvrumn8ug5rte5lbmnu45jvqefvr@4ax.com...

>> if ( CreateProcess( NULL, // Name of Application
>> "del bar*.*", // command line

>Did you test that? I would claim that you have to inform shellexecute that
>the REN command is inside CMD.exe .. that is "cmd /c ren .....". Also,

No, to be honest. I just took a snippet, that I use for a command not
build into cmd.exe, stripped my success- and error-handling and
replaced the command. Hoping, that Viviana will know (or learn) to use
"cmd /c", and preferring to give an example that's working for me.

Sorry, if I have caused confusion. Later on, I regretted this posting,
especially for cmd not being available everywhere, but was not
bothered enough to give this correction. Sorry again.

>i can't see why ShellExecute() couldn't be used as well.

Maybe, as well as system, spawn,...

I just happen to dislike the shellapi.

Andreas
--
Prosperity and ruin issue from the power of the tongue.
Therefore, guard yourself against thoughtless speech.

Re: Delete all files with "a pattern" by Viviana

Viviana
Thu May 27 05:49:28 CDT 2004

I actually implemented by browsing through the dir with FindFirstFile
and FindNextFile and delete the ones I was interested in.

Viv


On Mon, 24 May 2004 20:51:26 +0200, Andreas Hadler
<Andreas.Hadler@t-online.de> wrote :

>"Sten Westerback" <sten.westerback@NO_SPAMnokia.com> wrote:
>
>>
>>"Andreas Hadler" <Andreas.Hadler@t-online.de> wrote in message
>>news:27t4a0tvrumn8ug5rte5lbmnu45jvqefvr@4ax.com...
>
>>> if ( CreateProcess( NULL, // Name of Application
>>> "del bar*.*", // command line
>
>>Did you test that? I would claim that you have to inform shellexecute that
>>the REN command is inside CMD.exe .. that is "cmd /c ren .....". Also,
>
>No, to be honest. I just took a snippet, that I use for a command not
>build into cmd.exe, stripped my success- and error-handling and
>replaced the command. Hoping, that Viviana will know (or learn) to use
>"cmd /c", and preferring to give an example that's working for me.
>
>Sorry, if I have caused confusion. Later on, I regretted this posting,
>especially for cmd not being available everywhere, but was not
>bothered enough to give this correction. Sorry again.
>
>>i can't see why ShellExecute() couldn't be used as well.
>
>Maybe, as well as system, spawn,...
>
>I just happen to dislike the shellapi.
>
>Andreas