Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

  • *Experts*
Posted

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.

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

Posted

:D Forget about dos and batch file command buddy :cool: Here is vb.net code for you.

 

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

For i = 0 To UBound(fs)
    File.Delete(fs(i))
Next

Don't judge a man by his look. Don't judge a book by its cover. :D
  • Leaders
Posted

if you want to use the Dos method of deleting files from a folder, here's a quick sample i knocked up for you ...

       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 :)

Posted

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

 

Process.Start("c:\windows\system32\cmd.exe /c del *.bat")

Don't judge a man by his look. Don't judge a book by its cover. :D

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...