Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Looping While File is not realeased 1

Status
Not open for further replies.

zevw

MIS
Jul 3, 2001
697
US
I am unzipping a file with pkunzip and do not to go further till the file exists (unzipped)

This is the code

Code:
    ChDrive "F"
    ChDir "F:\Org\Import\Temp\"
    
    NW = Shell("F:\Org\pkzip\pkunzip.exe -o F:\Org\Import\Temp\Tmp.zip", vbMinimizedFocus)
    Do While Dir("F:\Org\Import\Temp\*.mdb") = ""
    Loop
    
    FileCopy "F:\Org\Import\Temp\" & FilNm & ".mdb", "F:\Org\Import\Old\" & FilNm & ".mdb"

My problem is that even though the file exists it was not released by Pkunzip and I would like to loop around until the file is released.

How can I verify that the file is not locked so that I can copy it?
 
Not sure if you are talking about the mdb being used when you say locked but, when an mdb is locked it creates and file with an extention of .ldb.

You can use the Dir function to see if it exist.

I hope I am going down the correct street.

ProDev, MS Access Applications
Visit me at ==>
May God bless you beyond your imagination!!!
 
How are ya zevw . . .

What you ask is a [blue]windows function[/blue], not an office or access function.

I havn't looked yet, but perhaps there's an [blue]API[/blue] for this. See All API

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
 
Actually I am using the Dir Function. It seems that the file does exist but is not yet released. My question is how can I see that its still locked.

I get an error message when running this line. (That is only when I run the program. Step by step debugging works fine, because its released with miliseconds).

Code:
FileCopy "F:\Org\Import\Temp\" & FilNm & ".mdb", "F:\Org\Import\Old\" & FilNm & ".mdb"

I was thinking of testing it with the IsError Function, something like to capture the error number and loop around trying to run this line, till the file is released. I just don't know how to capture the error!

Any suggestions would be of great help :)

 
How about using the Sleep API and put in say a half a second pause in the program?
 
I can put sleep or put a counter and count up to 6000000 or whatever.

That is only a patch, but I do believe that I can loop around to try a line of code and as long as it gives me a error I will stay in the loop and not go further.

I never used the IsError Function can that be used to test a line of code?
 
What about this ?
ChDrive "F"
ChDir "F:\Org\Import\Temp\"
NW = CreateObject("WScript.Shell").Run("F:\Org\pkzip\pkunzip.exe -o F:\Org\Import\Temp\Tmp.zip", 2, True)
FileCopy "F:\Org\Import\Temp\" & FilNm & ".mdb", "F:\Org\Import\Old\" & FilNm & ".mdb"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PH

I was really waiting for you to respond, because I knew you got the answer, "you always do". I am getting an error while running this line


Run-time error '-2147024894 (80070002)':

Method 'Run' of object 'IWshShell3' failed


Thanks for all your help!!
 
You could use error handling.

ChDrive "F"
ChDir "F:\Org\Import\Temp\"

NW = Shell("F:\Org\pkzip\pkunzip.exe -o F:\Org\Import\Temp\Tmp.zip", vbMinimizedFocus)
Do While Dir("F:\Org\Import\Temp\*.mdb") = ""
Loop

On Error GoTo Err_Handler

FileCopy "F:\Org\Import\Temp\" & FilNm & ".mdb", "F:\Org\Import\Old\" & FilNm & ".mdb"

Exit_Here:
Exit Sub

Err_Handler:
Resume 'it will loop forever until the file is unlocked


[pipe]
Daniel Vlas
Systems Consultant

 
Daniel

Thanks

It seems simple and straight forward, this is what I did.

Code:
Err_ImportData_Click:
    If Err.Number = 70 Then
        Resume
    Else
        MsgBox Err.Description
        Resume Exit_ImportData_Click
    End If

PH

I really would like to correct that error if you don't mind helping me figure out where I went wrong.

Thanks all of you for all your help :)
 
How are ya zevw . . .

In your post origination, your loop is very tight!. Although other processes may have priority its not known if pkunzip does.

Loosen up the loop a little and hand over ctl to other processes. It may do the trick . . .
Code:
[blue]   Do While Dir("F:\Org\Import\Temp\*.mdb") = ""
      [purple][b]DoEvents[/b][/purple]
   Loop
[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top