Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Locking the file while writing in PowerShell

Tags:

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?

like image 571
Deepak Avatar asked Dec 09 '22 10:12

Deepak


1 Answers

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()

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

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

like image 162
Vasili Syrakis Avatar answered Dec 16 '22 00:12

Vasili Syrakis