2011-05-27 54 views
0

我很好奇。如果我正在使用streamreader和streamwriter的组合,是否有一种方法可以让我只有在文件X被修改后才能写入流?使用StreamReader来确定文件是否已更改

此代码可能无法以最佳方式构建。它附在帮助我解答我的问题。

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") 
       End Using 
      Next 
    End Using 

回答

1

您可以拨打File.ReadAllText(path)获得包含文本字符串。

然后,您可以将新字符串与旧字符串进行比较。


读取命令的输出正确的方法是与RedirectStandardOutput使用Process class
然后,您可以在StandardOutput附近创建StreamReader,并致电ReadToEnd()

相关问题