Wrox Programmer Forums
|
Visual Basic 2005 Basics If you are new to Visual Basic programming with version 2005, this is the place to start your questions. For questions about the book: Beginning Visual Basic 2005 by Thearon Willis and Bryan Newsome, ISBN: 0-7645-7401-9 please, use this forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2005 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 6th, 2008, 01:57 AM
Registered User
 
Join Date: Aug 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to check a file status?

Hello.

Please help me with the question:

I am getting files from a directory, then I have to process them one by one (copy, move to another folder, and etc.). Before I will do anything with a file I must check if the file is not involved in any process (suppose it is already open or loading from another folder). If the file is under any process it should me moved to the end of its current directory and the second file should be processed; if it is the last file - program should pause and start over when the file will be available to process (I mean someone close the file or the file will be loaded completely).

The code should run in an automatic cycle, without any interaction with a user.

If it is hard maybe somebody knows how to check the file status. Spent a lot of time but did not find any useful information.

Thank you.

 
Old August 6th, 2008, 09:07 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Attempting to open the file for writing would probably qualify as a reasonable check that no-one else has a lock on it. You can then close it and continue with your process. If trying to open for writing throws an exception than either someone has a lock on it, or you don't have permissions for it. I don't know of a way to explicitly check for whether or not a file is in use. But then again, I'm not a System.IO expert so there's likely something I'm not aware of.

-Peter
compiledthoughts.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
check if file is already open carrie09 Excel VBA 4 September 5th, 2007 01:54 AM
check first to see if the file exists crmpicco Classic ASP Professional 2 December 1st, 2005 12:34 PM
check for file existance sentme_mail VB How-To 7 February 22nd, 2005 08:06 AM
check file open bala_7272 Visual C++ 1 September 15th, 2004 07:44 PM
check if file is an image file silver_cuts Classic ASP Basics 10 June 30th, 2004 12:33 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.