Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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.