My source file in CopyFile is sometimes locked and cannot be copied.
How can I find out if it is locked and so prevent the CopyFile from going ahead?
How to know when a source file is LOCKED.
Moderators: JRL, Dorian (MJT support)
- Bob Hansen
- Automation Wizard
- Posts: 2475
- Joined: Tue Sep 24, 2002 3:47 am
- Location: Salem, New Hampshire, US
- Contact:
It may depend on how the file is locked.
If it is made into ReadOnly, then this could work.
Read the Attributes of the file, then read the file and parse for results:
UNTESTED Structure to build on:
In that case use IFFileExists:
If it is made into ReadOnly, then this could work.
Read the Attributes of the file, then read the file and parse for results:
UNTESTED Structure to build on:
If it is like an Access database, then look for the existence of an "ldb" file with the same name as the database, like "DatabaseName.ldb". Different applications will follow a similar approach, making a locking file, then deleting it when no longer locked.//Write value of attributes to a text file
Run Program>command.com /c ATTRIB c:\folder\filename.ext > c:\temp\attrib.txt
//Make the text file a variable
ReadLn>c:\Temp\attrib.txt,Attrib
//Check for position of "R", I think it is in position 1
MidStr>%Attrib%,1,1,ReadOnly
//Split macro path depending on value of attribute
IF>%ReadOnly%=R,Locked
//File is not locked, continue to copy file
Goto>End
Label>Locked
//File is locked, cannot copy file
Label>End
In that case use IFFileExists:
IfFileExists>DataBaseName.ldb,Locked
//File is not locked, continue to copy file
Goto>End
Label>Locked
//File is locked, cannot copy file
Label>End
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!
Bob
A humble man and PROUD of it!
Or if it is locked for writing a method that has been used many times before is to try to write a dummy record to it. WriteLn will generate an error of the file is locked. So you just keep trying until you don't get an error:
Label>wloop
WriteLn>filename,r,
If>r=##ERR##,wloop
Label>wloop
WriteLn>filename,r,
If>r=##ERR##,wloop
MJT Net Support
[email protected]
[email protected]