gpt4 book ai didi

powershell - 读取后如何清除文件内容

转载 作者:行者123 更新时间:2023-12-03 01:02:59 37 4
gpt4 key购买 nike

读取数据和随后的文件清理操作必须在一个 session 中进行。和其他进程不应访问该文件。

$FileTwo = [System.io.File]::Open('C:\FiLeTwo.txt', "Open", "Read", "None") 
$FileTwo2 = New-Object System.IO.StreamReader($FileTwo)
$text = $text + $FileTwo2.ReadToEnd()

$text = $text -replace '\ ' -replace 'g' -replace '\(' -replace '\)' -replace $re, "" #-replace '\n'
# Set-Content 'C:\FiLeTwo.txt' "" -Force
# IN that moment I need to clear the file.
# But I need cleare the file and, after, close the File ($FileTwo.Close())

$FileTwo.Close()

最佳答案

您可以使用 Clear-Content删除文件的内容,但不删除它。

例子:Clear-Content c:\path\to\your\file.txt
你可以在这里读更多关于它的内容:
https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/clear-content?view=powershell-6

关于powershell - 读取后如何清除文件内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53279504/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com