Home All Groups Group Topic Archive Search About

How can I execute a simple command?

Author
7 Sep 2006 6:21 PM
Jeffrey Grantz
I have the following routine that I thought was streight forward (I should
know better)



Private Sub DOS_Command()

Dim lRetVal As Long

lRetVal = Shell("erase ""Z:\IDW2\XML Report Files\*.txt""")

End Sub

When the shell line gets executed, I get a diagnostic "Verify that the file
exists in the specified location".  The files are there.  If I go to a
command line and execute the same command. it performs fine.  Any ideas or
better ways to accomplish the same thing?

Author
7 Sep 2006 6:44 PM
S Kachru
I believe the Shell function is looking for the "erase" file/program and
since it can't find it, it's throwing an error. I don't know what your specific
requirements are, but there are different ways to achieve what you are trying
to do.




Show quoteHide quote
> I have the following routine that I thought was streight forward (I
> should know better)
>
> Private Sub DOS_Command()
>
> Dim lRetVal As Long
>
> lRetVal = Shell("erase ""Z:\IDW2\XML Report Files\*.txt""")
>
> End Sub
>
> When the shell line gets executed, I get a diagnostic "Verify that the
> file exists in the specified location".  The files are there.  If I go
> to a command line and execute the same command. it performs fine.  Any
> ideas or better ways to accomplish the same thing?
>
Author
7 Sep 2006 6:50 PM
AMercer
> Private Sub DOS_Command()
> Dim lRetVal As Long
> lRetVal = Shell("erase ""Z:\IDW2\XML Report Files\*.txt""")
> End Sub
>
> When the shell line gets executed, I get a diagnostic "Verify that the file
> exists in the specified location".  The files are there.  If I go to a
> command line and execute the same command. it performs fine.  Any ideas or
> better ways to accomplish the same thing?

Erase is an internal OS command, and the way you do this via Shell is to run
cmd.exe with appropriate arguments.  In other words, Shell runs an exe file,
and there is no erase.exe file to run, and that is the diagnostic's complaint.

An easier way might be vb's Kill, eg
  Kill("Z:\IDW2\XML Report Files\*.txt")
If memory serves, Kill takes wild cards.
Author
7 Sep 2006 7:00 PM
Jeffrey Grantz
Thank you, thank you.  KILL did it just fine.

Show quoteHide quote
"AMercer" <AMer***@discussions.microsoft.com> wrote in message
news:B6F399D9-500E-4DF1-B60C-C4B5CF2C8FF6@microsoft.com...
>> Private Sub DOS_Command()
>> Dim lRetVal As Long
>> lRetVal = Shell("erase ""Z:\IDW2\XML Report Files\*.txt""")
>> End Sub
>>
>> When the shell line gets executed, I get a diagnostic "Verify that the
>> file
>> exists in the specified location".  The files are there.  If I go to a
>> command line and execute the same command. it performs fine.  Any ideas
>> or
>> better ways to accomplish the same thing?
>
> Erase is an internal OS command, and the way you do this via Shell is to
> run
> cmd.exe with appropriate arguments.  In other words, Shell runs an exe
> file,
> and there is no erase.exe file to run, and that is the diagnostic's
> complaint.
>
> An easier way might be vb's Kill, eg
>  Kill("Z:\IDW2\XML Report Files\*.txt")
> If memory serves, Kill takes wild cards.
>
Author
7 Sep 2006 8:39 PM
zacks
Jeffrey Grantz wrote:
Show quoteHide quote
> Thank you, thank you.  KILL did it just fine.
>
> "AMercer" <AMer***@discussions.microsoft.com> wrote in message
> news:B6F399D9-500E-4DF1-B60C-C4B5CF2C8FF6@microsoft.com...
> >> Private Sub DOS_Command()
> >> Dim lRetVal As Long
> >> lRetVal = Shell("erase ""Z:\IDW2\XML Report Files\*.txt""")
> >> End Sub
> >>
> >> When the shell line gets executed, I get a diagnostic "Verify that the
> >> file
> >> exists in the specified location".  The files are there.  If I go to a
> >> command line and execute the same command. it performs fine.  Any ideas
> >> or
> >> better ways to accomplish the same thing?
> >
> > Erase is an internal OS command, and the way you do this via Shell is to
> > run
> > cmd.exe with appropriate arguments.  In other words, Shell runs an exe
> > file,
> > and there is no erase.exe file to run, and that is the diagnostic's
> > complaint.
> >
> > An easier way might be vb's Kill, eg
> >  Kill("Z:\IDW2\XML Report Files\*.txt")
> > If memory serves, Kill takes wild cards.
> >

And then there's always the "proper" .NET way, File.Delete.
Author
8 Sep 2006 2:22 PM
Brian Tkatch
Jeffrey Grantz wrote:
Show quoteHide quote
> I have the following routine that I thought was streight forward (I should
> know better)
>
>
>
> Private Sub DOS_Command()
>
> Dim lRetVal As Long
>
> lRetVal = Shell("erase ""Z:\IDW2\XML Report Files\*.txt""")
>
> End Sub
>
> When the shell line gets executed, I get a diagnostic "Verify that the file
> exists in the specified location".  The files are there.  If I go to a
> command line and execute the same command. it performs fine.  Any ideas or
> better ways to accomplish the same thing?

Being a DOS command, it should probably be run as: cmd /k erase .......

B.