How to use any dos command inside a VB .NET?

Worrow

Well-known member
Joined
Jul 10, 2003
Messages
67
I tried to call "del *.bak" inside my program with process.start. However, since del is not a file so it is not possible to use process.start to call it. I know there are other ways to do the same thing but I just want to use dos command. Any idea how?

Thanks in advance.
 
Have your program create a batch file that contains all the DOS
commands you want to execute. Then use Process.Start() to
run the batch.
 
:D Forget about dos and batch file command buddy :cool: Here is vb.net code for you.

Code:
Dim fs() As String, i As Integer
fs = Directory.GetFiles(Directory.GetCurrentDirectory, "*.bat")

For i = 0 To UBound(fs)
     File.Delete(fs(i))
Next
 
if you want to use the Dos method of deleting files from a folder, heres a quick sample i knocked up for you ...
Code:
        Dim pr As Process
        Dim args As New ProcessStartInfo("cmd.exe")
        With args
            .RedirectStandardInput = True
            .RedirectStandardOutput = True
            .UseShellExecute = False
            .WindowStyle = ProcessWindowStyle.Normal
        End With
        pr = Process.Start(args)
        /// now lets delete all files with a .txt extension from the folder C:\testing\
        /// you would obviously use *.bak instead of *.txt here ...
        pr.StandardInput.WriteLine("del C:\testing\*.txt" & Convert.ToChar(13)) /// chr(13) being Enter key.
        pr.CloseMainWindow()
hope it helps :)
 
Hi! Your technique is cool buddy, but in this situation is different. I think to put an elephant into a refrigerator, just open the door and put it in. So...

Code:
Process.Start("c:\windows\system32\cmd.exe /c del *.bat")
 
dragon4spys method is the best one.
 
Last edited by a moderator:
Back
Top