Jump to content

check if file is open before FileMove()


Recommended Posts

is there a way i can check if file is opened by another person? (flash .fla file)

i've tried testing and FileMove() works if file is not already opened, if i have the file open (in this case test.fla) and script runs FileMove fails silently, or at least dose not attempt to move the file, which is fine, but is there a way i can detect the file is already open so i can change the behaviour of the script to cover that possiblity.

this script runs over a lan, not sure if that will make any difference.

My AutoIt Scripts.- AutoHost and Password Enabler for Delta Force 2 Demo.| Caffine for Winamp 2.9x and WRS 2.0 | mp3 directory cleaner | CRAP DJ | A:B:J Radio Automation Software | FFMPEG batch conversion automator

Link to comment
Share on other sites

found a way, may of use to someone.

i figured if i know the FileMove() did not move the file because it was already opened then all i did was use FileExists() to check for the file in it's new location.

example:

FileMove($from, $to ,8)
If FileExists($to) Then
 ;file move successful! do stuff.
Else
 ;file not moved, possibly already open, do more stuff
EndIf

the reason for this madness is the script deploys template files on our file server, if a template is updated & requires redeployment to the project folder i have to be sure not to dick the files if the graphic designer/coders have already started work on it.

Edited by cyanidemonkey

My AutoIt Scripts.- AutoHost and Password Enabler for Delta Force 2 Demo.| Caffine for Winamp 2.9x and WRS 2.0 | mp3 directory cleaner | CRAP DJ | A:B:J Radio Automation Software | FFMPEG batch conversion automator

Link to comment
Share on other sites

cyanidemonkey

Try this:

Global Const $GENERIC_READ  = 0x80000000
Global Const $GENERIC_WRITE = 0x40000000
Global Const $OPEN_EXISTING = 3
Global Const $FILE_ATTRIBUTE_NORMAL = 0x80

$file = "d:\Base\work.dat"
If Not FileExists($file) Then Exit

$hFile = DllCall("kernel32.dll", "hwnd", "CreateFile", _
                  "str", $file, _
                  "int", BitOR($GENERIC_READ, $GENERIC_WRITE), _
                  "int", 0, _
                  "ptr", 0, _
                  "int", $OPEN_EXISTING, _
                  "int", $FILE_ATTRIBUTE_NORMAL, _
                  "int", 0)

If $hFile[0] = -1 Then
    MsgBox(48, "Warning", "File is open")
Else
    DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hFile[0])
EndIf
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...