开发者

Using StreamReader to determine if File has been changed

I am curious. If I am using a combination of streamreader and streamwriter is there a way that I can have a stream written only if File X has been modified?

This code may not be constructed in the best way. It is attached to help in getting my questions accross.

sCommand = "whoami.exe >> C:\Desktop\Test.txt"

Using swrr As New StreamWriter(File.Open(ErrorLog, FileMode.OpenOrCreate))
            For Each strUserName As String In strLines
                Shell("cmd.exe /c" & sCommand, AppWinStyle.Hide, True, )
                'command Cannot Execute, List Why and Move onto Next Command
                Using sr As New StreamReader(File.Open(Test.txt, FileMode.OpenOrCreate))
                    If '''??File has been modifed??''''' Then swrr.WriteLine("PASS") Else swrr.WriteLine("FAIL")
             开发者_JS百科   End Using
            Next
  End Using


You can call File.ReadAllText(path) to get a string containing the text.

You can then compare the new string to the old one.


The correct way to read the output of a command is to use the Process class with RedirectStandardOutput.
You can then create a StreamReader around StandardOutput and call ReadToEnd().

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜