Jump to content
Sign in to follow this  
cyanidemonkey

check if file is open before FileMove()

Recommended Posts

cyanidemonkey

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

Share this post


Link to post
Share on other sites
cyanidemonkey

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

Share this post


Link to post
Share on other sites
rasim

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
  • Like 1

Share this post


Link to post
Share on other sites
ludocus

why dont you just do:

If ProcessExist('blabla.exe') then msgbox(0, 'Aargghh!', 'Files is open..')

Share this post


Link to post
Share on other sites
ludocus

why dont you just do:

If ProcessExist('blabla.exe') then msgbox(0, 'Aargghh!', 'Files is open..')

Share this post


Link to post
Share on other sites
rasim

ludocus

Example: User want to move media-file (e.g. test.avi), as i can know, what the program user used and than check this? ;)

Share this post


Link to post
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
Sign in to follow this  

×