Check whether file exists |
Author: |
Message: |
ryxdp
Senior Member
Posts: 804 Reputation: 16
30 / /
Joined: Jun 2006
|
O.P. Check whether file exists
More VB 2005 Express dilemmas .
I need a way of finding out whether a file exists (i know this bit), but it needs to keep on checking from Form1.Load to kill.
I don't like using timers.
Is it possible?
|
|
04-04-2007 07:13 AM |
|
|
vikke
Senior Member
Posts: 900 Reputation: 28
31 / /
Joined: May 2006
|
RE: Check whether file exists
You can start with telling us what programming language you're programming. If you're programming with the Win32 API, you should use CreateFileEx.
If you're using a dotNet based language, I think you can find it easily at Google.
vikke
|
|
04-04-2007 07:26 AM |
|
|
TheSteve
Full Member
The Man from Japan
Posts: 179 Reputation: 23
40 / /
Joined: Aug 2005
|
RE: RE: Check whether file exists
quote: Originally posted by vikke
you should use CreateFileEx.
There is no CreateFileEx... How about CreateFile instead?
If the file fails to open, make sure that GetLastError returns ERROR_FILE_NOT_FOUND or ERROR_PATH_NOT_FOUND or ther could be some other issue other than a missing file.
However you choose to keep checking you've got to put forth some effort. A thread is more difficult in some languages than timers.
This post was edited on 04-04-2007 at 09:01 AM by TheSteve.
|
|
04-04-2007 08:57 AM |
|
|
vikke
Senior Member
Posts: 900 Reputation: 28
31 / /
Joined: May 2006
|
RE: Check whether file exists
Yeah, my bad, I meant CreateFile.
And make sure you call GetLastError directly after your CreateFile call, otherwise you could get: "Error: Operation Successfully Completed".
vikke
|
|
04-04-2007 09:00 AM |
|
|
TheSteve
Full Member
The Man from Japan
Posts: 179 Reputation: 23
40 / /
Joined: Aug 2005
|
RE: Check whether file exists
|
|
04-04-2007 09:04 AM |
|
|
Ezra
Veteran Member
Forgiveness is between them and God
Posts: 1960 Reputation: 31
37 / /
Joined: Mar 2003
|
RE: Check whether file exists
I think he already knows how to check if a file exists, but he wants to know a way to keep continually checking untill the program exits. Without using Timers
I think the best way is to check if the file exists the first time and after that register a handle to watch filechanges in that directory.
EDIT: Watching filechanges is possible with FileSystemWatcher in .NET
This post was edited on 04-04-2007 at 09:29 AM by Ezra.
|
|
04-04-2007 09:28 AM |
|
|
vikke
Senior Member
Posts: 900 Reputation: 28
31 / /
Joined: May 2006
|
RE: Check whether file exists
If you open a file with CreateFile, the file cannot get deleted, only renamed.
If you don't want it to get removed, that's probably the best way.
vikke
|
|
04-04-2007 09:39 AM |
|
|
ryxdp
Senior Member
Posts: 804 Reputation: 16
30 / /
Joined: Jun 2006
|
O.P. RE: Check whether file exists
quote: Originally posted by vikke
You can start with telling us what programming language you're programming.
quote: Originally posted by me
More VB 2005 Express dilemmas
The program it needs to be in opens and sends a file, to be exact "PP5022.mi4" to a dynamic drive label, and all the while there is a Label that will either say "Theme not loaded. Please load theme." or "Theme loaded". Is there something you can put in Form1.Load that will just keep on checking?
If you don't get me, here's the diagram as I see it:
Private Sub Form1.Load [all the rest of that args stuff]
If Form1.Active Then
Keep.On.Checking.If.File.Exists(tillKill)
Using My.Computer.FileSystem.FileExists("E:\PP5022.mi4")
|
|
04-04-2007 10:14 AM |
|
|
Ezra
Veteran Member
Forgiveness is between them and God
Posts: 1960 Reputation: 31
37 / /
Joined: Mar 2003
|
RE: Check whether file exists
quote: Originally posted by Ryxpia
The program it needs to be in opens and sends a file, to be exact "PP5022.mi4" to a dynamic drive label, and all the while there is a Label that will either say "Theme not loaded. Please load theme." or "Theme loaded". Is there something you can put in Form1.Load that will just keep on checking?
If you don't get me, here's the diagram as I see it:
Private Sub Form1.Load [all the rest of that args stuff]
If Form1.Active Then
Keep.On.Checking.If.File.Exists(tillKill)
Using My.Computer.FileSystem.FileExists("E:\PP5022.mi4")
Like I said, first do a check to see if the file exists the normal way,
If it exists then register a filesystemwatcher event 'to see file changes in the folder where that file is placed
'now everytime a file gets deleted the function you registered will fire, in this function just
check if the deleted file is that file.
|
|
04-04-2007 10:22 AM |
|
|
John Anderton
Elite Member
Posts: 3908 Reputation: 80
37 / /
Joined: Nov 2004
Status: Away
|
RE: Check whether file exists
Never tried this in .NET but I suppose the classic, create a file pointer and check if its null should work perfectly fine
ie handle to file is null, file doesn't exist, else it does
[
KarunAB.com]
[img]http://gamercards.exophase.com/459422.png[
/img]
|
|
04-04-2007 10:39 AM |
|
|
Pages: (2):
« First
[ 1 ]
2
»
Last »
|
|