Good try though. Example: open a file with wordpad, ran openfile and get x number of instances of wordpad but none of them actually return the file name as it is called. This is not universal and reliable method for what is needed here. You are forgetting that a file has many open modes. Testing for an file by opening it requires opening it in all modes which cannot be done from script.
You do not want to set the global flag as it will slow your systems down. It is there for debugging mostly. To set it requires that Windows no track every file open in a memory structure.
This can be costly. The answer is and has been since the first version of Windows NT - you cannot detect a file open correctly with a script. We are getting off topic here again. Idea is that an application is writing to a file. I do not know whether during my script being run the application is still writing data to it or not.
Therefore need to know whether the file is open. WMI method if it was implemented would have been ideal as you could just check for that particular file having some sort of system flag against it saying it is in use by another application.
Instead I'm having to use FileSystemObject to Open file for writing in order to check whether the file can be moved elsewhere and processed further. Before posting here I have spent few hours in "my favorite search engine" trying to find a more efficient answer but couldn't hence this post. For example on other operating system I can just run touch and know straight away.
Simple and efficient. And that is what I'm trying to find here. It doesn't matter. What you are trying to do will not work as expected if the file belongs to a process that is using it in a certain way. Just move the file and duck. You are making too much of a simple thing. You cannot know if another process is using the file. Many file including most log files can be moved.
The process will just recreate the file if it is not in place. If you get an error then the file cannot be moved. This is all that is important. There is and cannot be a more efficient way. The whole concept on any OS is odd because you cannot move open file no matter what utility you use to get the status. The error you get is as fast or faster than any utility.
We thought you wanted to know this because there are legitimate technical reasons to finding open files. What you want cannot be done with a script. Don't be a Stranger! Sign up! View more:. Scripting Questions. Unassigned Ticket Notification Rule. Trying to run a Script that keeps failing. Getting Status code I am able to run the batch file from command prompt it works just fine. But when trying run it through kace it fails.
Remove an Agent from the K Console via a Script. Access denied copying files during a managed installation script. Echo "Media file not in use. Ansgar Wiechers Ansgar Wiechers k 23 23 gold badges silver badges bronze badges. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Podcast Making Agile work for data science.
Stack Gives Back Featured on Meta. New post summary designs on greatest hits now, everywhere else eventually. Linked 6.
0コメント