shell 强制覆盖文件夹,我怎么能强制PowerShell脚本等待,直到其他进程读完它覆盖文件?...

Imagine that I have a shared folder MyShared:

User A, gets the file \MyShared:\Foo.txt after every 30 seconds.

And I overwrite \MyShared:\Foo.txt also after every 28 seconds (within my PowerShell script)

How can I prevent myself to overwrite this file while the user is getting it, in PowerShell?

(I do not want to break the content of the file or end-up with some error by attempting to overwrite it in the time of user retrieving it)

If I rephrase the question:

How can I force a Powershell script to wait overwriting a file until another process is finished reading it?

解决方案

In some cases, you may not be able to overwrite it if the file is open.

Otherwise, you will have to devise some other mechanism to signal that the reader has finished reading it. This is not really related to powershell. For example, the reader can create a "lock file" to notify the writer that the file is being read, which it deletes after completing the read. The powershell script can delete the file if the lock file does not exist.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值