|
-
Dec 5th, 2006, 05:54 AM
#1
Thread Starter
Hyperactive Member
process call error
Hi
I am running the below mention code in vb.net but problem is
when dir.txt already in c: drive it will read the text file
but if i delete the dir.txt file and create new one and in next line
try to read the same dir.txt file it will flash error "Could not find file c:\dir.txt"
Pls guide me .. why this type of problem accured..
thanks
asm
VB Code:
Imports System
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim SFile As System.IO.File
Dim VolRead As System.IO.StreamReader
Dim ReadTxt As String
Try
If SFile.Exists("C:\DIR.TXT") Then
System.Diagnostics.Process.Start("C:\Windows\System32\CMD.exe", " /C Del C:\DIR.TXT")
End If
System.Diagnostics.Process.Start("C:\Windows\System32\CMD.exe", " /C Dir C: > C:\DIR.TXT")
VolRead = New System.IO.StreamReader("C:\DIR.TXT")
ReadTxt = VolRead.ReadToEnd()
Label1.Text = "READING TEXT FILE OK.."
VolRead.Close()
If SFile.Exists("C:\Dir.txt") Then
System.Diagnostics.Process.Start("C:\Windows\System32\CMD.exe", " /C Del C:\DIR.TXT")
End If
Catch ex As Exception
Label1.Text = ex.Message
End Try
End Sub
-
Dec 5th, 2006, 10:15 AM
#2
Re: process call error
Probably because it is running that line of code before the process finishes. You can either sleep the thread for a few milliseconds (System.Threading.Thread.Sleep), or even better create a new process object, start it, and use the .WaitForExit method of the process object to halt code execution until the process finishes.
However, you can just re-write the code to do what you want without using cmd.exe... there are classes to handle file and folder information on the system...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|