What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » Check whether file exists

Pages: (2): « First [ 1 ] 2 » Last »
Check whether file exists
Author: Message:
ryxdp
Senior Member
****


Posts: 804
Reputation: 16
29 / Male / Flag
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
Profile PM Find Quote Report
vikke
Senior Member
****

Avatar

Posts: 900
Reputation: 28
31 / Male / Flag
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
4 8 15 16 23 42
04-04-2007 07:26 AM
Profile E-Mail PM Find Quote Report
TheSteve
Full Member
***

Avatar
The Man from Japan

Posts: 179
Reputation: 23
40 / Male / Flag
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
Profile PM Web Find Quote Report
vikke
Senior Member
****

Avatar

Posts: 900
Reputation: 28
31 / Male / Flag
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
4 8 15 16 23 42
04-04-2007 09:00 AM
Profile E-Mail PM Find Quote Report
TheSteve
Full Member
***

Avatar
The Man from Japan

Posts: 179
Reputation: 23
40 / Male / Flag
Joined: Aug 2005
RE: Check whether file exists
If you're using .NET, this may be of some interest.
http://msdn2.microsoft.com/en-us/library/system.io.file.exists.aspx
04-04-2007 09:04 AM
Profile PM Web Find Quote Report
Ezra
Veteran Member
*****

Avatar
Forgiveness is between them and God

Posts: 1960
Reputation: 31
37 / Male / Flag
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.
[Image: 1-0.png]
             
04-04-2007 09:28 AM
Profile PM Web Find Quote Report
vikke
Senior Member
****

Avatar

Posts: 900
Reputation: 28
31 / Male / Flag
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
4 8 15 16 23 42
04-04-2007 09:39 AM
Profile E-Mail PM Find Quote Report
ryxdp
Senior Member
****


Posts: 804
Reputation: 16
29 / Male / Flag
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
Profile PM Find Quote Report
Ezra
Veteran Member
*****

Avatar
Forgiveness is between them and God

Posts: 1960
Reputation: 31
37 / Male / Flag
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.
[Image: 1-0.png]
             
04-04-2007 10:22 AM
Profile PM Web Find Quote Report
John Anderton
Elite Member
*****

Avatar

Posts: 3908
Reputation: 80
37 / Male / Flag
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
Profile E-Mail PM Web Find Quote Report
Pages: (2): « First [ 1 ] 2 » Last »
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On