Re: is file exist




"Victor Bazarov" <v.Abazarov@xxxxxxxxxxxx> wrote in message
news:%23%23HytNSbGHA.1220@xxxxxxxxxxxxxxxxxxxxxxx
ma wrote:
I need to check for existence of a file in current directory. I did
write my code that consists of opening it and if opening fails, I
could understand that the file doesn't exist. It is working but I
don't think it is the best solution. What is the best solution? Is
there any function that I can use for this purpose? Is there any
source code or sample on this?

Generally speaking, if you need to read a file, opening it for reading and
checking success is what you are supposed to do. If you need to write
a file, opening it for writing and checking success is what you're
supposed
to do. What do you need to check the existence of the file for? Is it
used
as some kind of semaphore? Then it probably contains some information
that
might be useful, so open it for reading and read (if it opens).

There are file functions in Windows API, like CreateFile, which extend the
plain ol' "open" functionality of the standard C library. Check it out.
And I bet the manual does contain a decent example of using 'CreateFile'.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask

Hello,
I have a library with a function in it that get a file name and download
it to a hardware. The problem with this function is that if it fails it
doesn't give me any clue why it fails. One important way that it may fail is
when the file isn't available. So I need to check if the file is exist.

One other situation that I can see if I want to see if there is a file in
path and if it is , what is its full path. How can I do this? I know that I
can use findfile and findnext, but is there any better way to do this?

best regards



.



Relevant Pages

  • Re: documents with tables wont open
    ... If you saved the files directly from Word to your CD, chances are you ... corrupted them -- saving files directly to removable medium often does that. ... property, then try opening them. ... If it still fails, try Word's Recover Text ...
    (microsoft.public.word.docmanagement)
  • Re: Is it correct about File.createNewFile()?
    ... that File instance to recreate the same file again fails ... and opening a stream of that file reads back no data, ... the spec is being fulfilled. ...
    (comp.lang.java.programmer)
  • Re: is file exist
    ... write my code that consists of opening it and if opening fails, ... checking success is what you are supposed to do. ... so open it for reading and read (if it opens). ...
    (microsoft.public.vc.language)
  • Re: Code looping through files
    ... Since you don't show the code, have him send you the file that fails to open ... a folder, opens each, does things, closes the file and opens the next ... fails on opening the first file for him. ... XLSTART folder. ...
    (microsoft.public.excel.programming)
  • Re: Corrupt word file
    ... Try using File Open and select the Open and Repair option. ... fails, then you could try opening it in WordPad or a basic text editor which ...
    (microsoft.public.word.application.errors)