How can I execute a simple command?

J

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?
 
S

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.
 
G

Guest

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.
 
J

Jeffrey Grantz

Thank you, thank you. KILL did it just fine.

AMercer said:
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.
 
B

Brian Tkatch

Jeffrey said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top