Jump to content

File Open/File In Use Test


Recommended Posts

I'm doing some automation with .RTF files that are created with an editor called DragonPad.exe.

Unlike Microsoft Word, which is civilized enough to set the system file status to locked when it is open, DragonPad does not practice such niceties (apparently neither does notepad or wordpad).

Therefore:

$file = FileOpen($filename, 1)
If $file = -1 Then MsgBox(0, "FILE OPEN ERROR" ,"File in use: " & $filename)
Does not work.

I've having instances where users have opened, modified, and then sent a .RTF file for processing (via my script) prior to saving their latest changes, resulting in the loss of information.

I could put the responsibility on them, and pop up a reminder asking them to ensure they have saved their file.

Or, I could check if the DragonPad.exe process exists and ask them to close it, but that assumes they are editing the file to be processed, which may not be the case.

A couple searches turned up little of use. Are there any better methods to test if a specific file is open with programs such as notepad, wordpad, or dragonpad?

Thank you.

Edit: Can one enumerate which file handles are being used by a particular process, and then associate each handle with the actual filename on disk?

Edited by Spiff59
Link to comment
Share on other sites

Here's something that may work for you:

$file = "test.txt"
$origDir = @ScriptDir

FileCopy($origDir & "\" & $file, @TempDir & "\" & "temp_" & $file, 1)
FileSetAttrib ($origDir & "\" & $file, "R")
ShellExecuteWait(@TempDir& "\" & "temp_" & $file)
FileSetAttrib ($origDir & "\" & $file, "-R+N")

FileMove(@TempDir & "\" & "temp_" & $file, $origDir & "\" & $file, 1)
FileDelete(@TempDir & "\" & "temp_" & $file)

#include <ByteMe.au3>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...