mdwerne Posted January 21, 2009 Share Posted January 21, 2009 Hello, Is there anyway with Autoit to test if a file is locked and by whom (what process)? I'm trying to replace some log files (all xml) in a folder and sometimes the replacement works fine, and sometimes it fails and one of the files has not been replaced. That's why I need a suggestion regarding my question above. Thanks, -Mike Link to comment Share on other sites More sharing options...
NerdFencer Posted January 21, 2009 Share Posted January 21, 2009 Try using FileGetAttrib _________[u]UDFs[/u]_________-Mouse UDF-Math UDF-Misc Constants-Uninstaller Shell Link to comment Share on other sites More sharing options...
mdwerne Posted January 21, 2009 Author Share Posted January 21, 2009 (edited) Try using FileGetAttribHi NerdFencer,Thanks a lot for the suggestion. Sadly I tested all the attribs and Archive is the only one that came back as true. When I try and manually delete the file, I get an error that the action can't be completed because the file is open in another program.Any other thoughts/suggestions?-Mike Edited January 21, 2009 by mdwerne Link to comment Share on other sites More sharing options...
CodyBarrett Posted January 22, 2009 Share Posted January 22, 2009 well is it read only? filegetattrib() if 'R' then.... or what do you mean by LOCKED? [size="1"][font="Tahoma"][COMPLETED]-----[FAILED]-----[ONGOING]VolumeControl|Binary Converter|CPU Usage| Mouse Wrap |WinHide|Word Scrammbler|LOCKER|SCREEN FREEZE|Decisions Decisions|Version UDF|Recast Desktop Mask|TCP Multiclient EXAMPLE|BTCP|LANCR|UDP serverless|AIOCR|OECR|Recast Messenger|AU3C|Tik-Tak-Toe|Snakes & Ladders|BattleShips|TRON|SNAKE_____________________[u]I love the Helpfile it is my best friend.[/u][/font][/size] Link to comment Share on other sites More sharing options...
Drew Posted January 22, 2009 Share Posted January 22, 2009 Restart your computer and delete it. Occasionally things you close , the computer believes is still running in the background. If its something to the extent of Process Manager ( CTRL + ALT + DEL ) than just close it there. But I have this happen sometimes =/. Its usually just things running in the background. Link to comment Share on other sites More sharing options...
mdwerne Posted January 22, 2009 Author Share Posted January 22, 2009 (edited) well is it read only? filegetattrib() if 'R' then.... or what do you mean by LOCKED?Hi Bob, Sorry for my lack of clarification. The file is not necessarily locked from writing (attrib = R) it is locked (open) by a running process/service so I can't delete or replace it . My question was really twofold. 1) How can query/test a single file to see if it is locked (or not) by "something" so that I can determine if I can make changes to it. Specifically delete it. 2) If I can tell if the file is locked, can I determine what process or service has it locked. That way maybe I can kill the process or stop the service temporarily and make my changes. Here is a rough example using some imaginary functions... $fileinquestion = ("C:\tempfile.xml") if _IsFileLocked($fileinquestion) = 1 then $processinquestion = _ProcessOfLockedFile($fileinquestion) ProcessClose($processinquestion) FileDelete($fileinquestion) else FileDelete($fileinquestion) endif I hope all this helps to clarify my question. So far all my searches of the forum and Google have come up null with regard to testing a file for a locked(open/in use) state. Thanks for the reply. -Mike Edited January 22, 2009 by mdwerne Link to comment Share on other sites More sharing options...
mdwerne Posted January 22, 2009 Author Share Posted January 22, 2009 Restart your computer and delete it. Occasionally things you close , the computer believes is still running in the background.If its something to the extent of Process Manager ( CTRL + ALT + DEL ) than just close it there.But I have this happen sometimes =/. Its usually just things running in the background.Hi Drew,Yeah...unfortunately it's more than just a reboot. Whatever process has the strangle hold may or may not be running at any given point. Upon reboot, the same situation will exist. Your right about killing the process, but my goal is to test the file programatically and not have to do anything by hand.Thanks for the input!-Mike Link to comment Share on other sites More sharing options...
KaFu Posted January 22, 2009 Share Posted January 22, 2009 (edited) Is there anyway with Autoit to test if a file is locked...#571583...and by whom (what process)?Not that I know of any AU method, try http://ccollomb.free.fr/unlocker/ , maybe you can use the dll files (for private versions only of course )....orWhen you know the file is locked, try to delete it and Unlocker will tell you the process... then in your script check for _FileInUse() and kill the process determined with Unlocker ...Edit: Changed post of _FileInUse() Edited January 22, 2009 by KaFu OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
mdwerne Posted January 22, 2009 Author Share Posted January 22, 2009 #571583Not that I know of any AU method, try http://ccollomb.free.fr/unlocker/ , maybe you can use the dll files (for private versions only of course )....orWhen you know the file is locked, try to delete it and Unlocker will tell you the process... then in your script check for _FileInUse() and kill the process determined with Unlocker ...Edit: Changed post of _FileInUse()KaFu,The example by Siao in your first link worked PERFECTLY! Gave me a return value that I can work with. I'm hesitant to use a third party product. I'd really like to do this all in Autoit. But for testing sake...I will give it a shot. Thanks for the tip!!-Mike Link to comment Share on other sites More sharing options...
KaFu Posted January 22, 2009 Share Posted January 22, 2009 I'm hesitant to use a third party product. I'd really like to do this all in Autoit.Just use it to determine the process... to kill with AU later on ... this works at least if it's always the same and only one process... OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 22, 2009 Moderators Share Posted January 22, 2009 KaFu, My thanks too. I searched for something like this in the forums but never found it. If you do not use the correct terms to search for it can be really frustrating at times! M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
groovy Posted January 22, 2009 Share Posted January 22, 2009 Try using FileGetAttrib Link to comment Share on other sites More sharing options...
SD097 Posted June 4, 2022 Share Posted June 4, 2022 You could also try: Local $iFileExists = FileExists($sFilePath) Local $hFileLockTest = FileOpen($filename, $FO_READ) if $iFileExists = 1 And $hFileLockTest = -1 Then ; this file is locked! Else FileClose($hFileLockTest) FileDelete($filename) ; from FileDelete: 'Some file attributes can make the deletion impossible, if this is the case look at FileSetAttrib() to change the attributes of a file.' EndIf Link to comment Share on other sites More sharing options...
Developers Jos Posted June 4, 2022 Developers Share Posted June 4, 2022 mmm ... do you seriously thinks the OP is still looking for an answer to a question asked 13 years ago? SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
SD097 Posted June 4, 2022 Share Posted June 4, 2022 Not particularly. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now