powershell - 在PowerShell中写入时锁定文件

标签 powershell

我有一个要求,即一个进程连续写入特定文件夹中的文件。同时,另一个脚本将文件从该文件夹移动到另一个文件夹。但是,在第一个过程正在写入文件的过程中,不得移动文件。 PowerShell中是否有任何可以满足此要求的进程/功能?

最佳答案

在Powershell中,语法如下:

$path = "C:\file.txt"
$mode = "Open"
$access = "Read"
$share = "None"

$file = [System.IO.File]::Open($path, $mode, $access, $share)
$file.close()

以下网址提供了有关该类的更多信息:

http://msdn.microsoft.com/en-us/library/y973b725(v=vs.110).aspx

关于powershell - 在PowerShell中写入时锁定文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21086051/

相关文章:

Powershell 不加载 System.Net.Http 程序集并忽略脚本中的 Add-Type

windows - 需要在 github 操作工作流程中将反斜杠转换为正斜杠

powershell - 如何将命名参数传递给Powershell中的另一个脚本

powershell - [Environment]::SetEnvironmentVariable 未永久设置

excel - 启动 Excel 时出现错误 "Retrieving the COM class factory for component with CLSID"

powershell - 压缩存档错误 : PermissionDenied

PowerShell 在逗号或空格后修剪姓氏

PowerShell 成员 : explanation for Methods and Properties?

powershell - 导出 CSV 文件中的多个对象 PowerShell

powershell - Powershell变量分配与管道