How do i see if file exists - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

How do i see if file exists

cloudncalicloudncali Posts: 35Member
[b][red]This message was edited by cloudncali at 2006-6-16 8:9:26[/red][/b][hr]
is there a funtion to see if a filem exsists in a folder

if not how can i make one

Comments

  • MFHMFH Posts: 56Member
    : [b][red]This message was edited by cloudncali at 2006-6-16 8:9:26[/red][/b][hr]
    : is there a funtion to see if a filem exsists in a folder
    :
    : if not how can i make one
    :
    I don't know if a function exists, but when you try to open an unexisting file it generates an error, so you can use this to create your own function. Try with something like this:

    [code]public function ExistsFile (path as string) as boolean
    dim Useless as boolean
    Useless = true

    on error goto EndOfFunction

    open path for input as #1
    close #1
    ExistsFile = true

    if Useless = false then
    EndOfFunciton:
    ExisitsFile = false
    end if

    end function[/code]

    The way it works is very simple: the function tries to open the file, if it succeed ExisitsFile is true, if not it generates an error and the function goes in a "restricted area" and ExistsFile is false.

    I'm quite sure that the function can be improved, but for the moment it should work.
  • dokken2dokken2 Posts: 532Member
    : : [b][red]This message was edited by cloudncali at 2006-6-16 8:9:26[/red][/b][hr]
    : : is there a funtion to see if a filem exsists in a folder
    : :
    : : if not how can i make one
    : :


    you can use the DIR keyword-

    [code]
    dim tmp as string
    tmp = dir("c:WINDOWSSYSTEM32CALC.EXE")
    if tmp<>"" then
    debug.print "file exists"
    else
    debug.print "file not found"
    end if
    [/code]

Sign In or Register to comment.