Windows 10中的索引值-1

时间:2019-05-29 05:49:10

标签: powershell

我有一个在Windows 7中可以正常工作的代码段,但是在Windows 10中执行时,输出与Windows 7不同,索引值为-1

我尝试使用IndexOf,LastIndexOf,但仍然没有进展

$a = (Get-Item c:\Temp\*.exe)

$b = $a.basename

$b

$search = 'Location: C:\Users\Desktop\'+$b+'.exe'

$c   = Get-Content -Path "c:\Temp\abc.txt"

$d = $c.Length

$d

$data   = Get-Content -Path "c:\Temp\abc.txt" |Out-String

$index  = $data.LastIndexOf($search) - $d  

$index  = $data.Substring($index) 

$index

我想从头开始读取abc.txt文件,直到$ search,输出必须一直到search。 abc.txt文件不断追加内容,因此我需要从末尾开始最新的追加。在Windows 7中我可以获取,但在Windows 10中,我收到的索引值为-1。另外,我也不想使用尾巴。

0 个答案:

没有答案