在 PowerShell 中写入时锁定文件 [英] Locking the file while writing in PowerShell

查看:65
本文介绍了在 PowerShell 中写入时锁定文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a requirement where one process continuously writes to the files in a particular folder. At the same time an another script moves the files from that folder to another folder. But files must not be moved while the first process is in the middle of writing to them. Is there any process/function in PowerShell which can fulfill this requirement?

推荐答案

Powershell 中的语法如下:

In Powershell the syntax is like this:

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

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

<小时>

在以下 URL 上有关于这个类的更多信息:


There is more information available on this Class at the following URL:

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

这篇关于在 PowerShell 中写入时锁定文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆