check to see if a file is locked


How do we check to see if a .rar/.zip file is locked, using SSIS? If it is locked, then the package should stop executing. If the file is not locked, then it should unzip/extract/decompress the file using pkzip in the execute process task. How do we accomplish this using SSIS 2005. We should be using only PKZIP to decompress the file. What is the command that should be used to unzip/extract/decompress the file using pkzip.

Thanks  a million in advance.

Any logic/code is greatly appreciated. Can someone help me with this ASAP. I'm not permitted to install any additional zip/unzip software on the server.

I greatly appreciate your help ASAP.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Anthony PerkinsCommented:
For the record, this is a continuation of this thread:
Well, you could use an Execute Process task to run a batch file to unzip:
pkunzip sourcefilename, targetfilename
exit /B 0

Open in new window

The last line means that it always returns success. Next, continue if the unzipped targetfile exists, and not if not. You can do this by running a foreach container for each instance of the targetfile (only ever one!) - if it exists then the file wasn't locked and you loop one time. If the file was locked no targetfile exists and the loop never executes.

I actually have something similar - an FTP job to download a large file. However, I can't download it until it's all finished being uploaded to the FTP site! We wrote a small Python program that looks at the file date/time and size every few minutes and compares it with the previous results. If it hasn't changed then we're ready to download! You might want to try doing something like that, but with the attributes of the Zip file.

Another possibility, if you're allowed, is to get the package of SSIS tasks from PragmaticWorks. The free package contains a task to return info about a file and I think it might tell you the locked status, although I'm not sure.



Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
amuktaAuthor Commented:
Thank you Mike,

I need to only unzip the files if they are not locked.if atleast one file is locked, my SSIS package should stop executing.i found some code online to check to see if the files are locked. But the file status of .rar/.zip is always always being shown as locked, even when they are not locked. Is there any special way of checking these files using a script task?
What if you did something that would fail if it is locked?

Like maybe use a script task to rename to or move the file into another subfolder named ..\ready or something like that.

Maybe even use error handling and a loop.... if it fails, pause 30 seconds and try again... for up to a max of 10 retries....  that would be pretty cool.  You could make it send an email if it was still locked after the max number of retries.
I think you may be looking in the wrong place if you're seeing the .zip files as always locked - or else the creation program hasn't finished with them yet.

You might try running the unzip on them from a batch file and seeing - if they unzip regardless then it really doesn't much matter whether you think that they're locked or not ...

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.