0

I have an infinity loop process. I will check a file, once the file exist, then I process it. Is it possible if I found the file, then I lock it, so people will not able to open or modify the file until the process finish.

do{
     if(Test-Path -Path ".\Data.txt")
     {
          $file = Get-content -Path ".\Data.txt"
          ## do some process ##
          #
          #
          #
          #
          #modify the file extension to .don once
          # process
          #
          #FINISHED (the process will finished once the extension modified)
     }
}

while(1)

Anyone can give idea please. Thank you.

Cheries
  • 834
  • 1
  • 13
  • 32
  • You don't have to lock it. As you want to rename it anyway: Use the content of `$file` that cannot be changed by users anyway, create a new file with this content and the `.don` ending and delete the old file with `.txt` ending, no matter if someone changed it in the meantime. – stackprotector Jun 12 '20 at 08:46
  • Thankyou. But I don't want to create a new file. @Thomas – Cheries Jun 12 '20 at 08:53
  • Then you might want to have a look at [this question](https://stackoverflow.com/q/26156715/11942268). – stackprotector Jun 12 '20 at 09:02

0 Answers0