evergreean43
Technical User
I have a small script that works where it copies a file from one Windows server to another. The destination file is always overwritten.
Now I think I should check if the file I am copying from (sourceFile) is opened by someone and also check if the file I am copying to (destinationFile) is being used.
Here is my current copy command:
Please advise how I can do this because I am not sure about opening it up and how flock works?
Now I think I should check if the file I am copying from (sourceFile) is opened by someone and also check if the file I am copying to (destinationFile) is being used.
Here is my current copy command:
Code:
Use File::Copy
...
copy($sourceFile,$destinationFile) || die "$!";
Please advise how I can do this because I am not sure about opening it up and how flock works?
Code:
open(INPUT, "<$sourceFile");
@data = <INPUT>;
close(INPUT);
open (OUTPUT, ">$sourceFile");
flock(OUTPUT, 2);
copy($sourceFile,$destinationFile) || die "$!";