Results 1 to 5 of 5

Thread: Existing txt File

  1. #1

    Thread Starter
    Addicted Member Abrium's Avatar
    Join Date
    Feb 2007
    Location
    The Great State of Texas
    Posts
    205

    Existing txt File

    Hey all,

    What is the simplest way to check for an existing file. Every method shown to me in my text and the information gained from the Visual Studio help doesn't seem to work. Each one of them tells me the syntax is wrong. I just want a simple way to check for an existing text file that is in the defualt file location.

    MSDN told me to use FileSystem.FileExists(file) - VS would not take this and...

    My text Tony Gaddis (VB 2008) shows:
    Code:
    If File.Exists(FileName) Then
    open file...
    Else
    Create file
    End If
    Neither of these work and I am getting frustrated as hell with this simple task! Can anyone throw me a simple fuction to use in this situation?
    Abrium
    Asking the beginners questions so you don't have to!
    If by chance hell actually froze over and I some how helped you... Please rate.

  2. #2

    Thread Starter
    Addicted Member Abrium's Avatar
    Join Date
    Feb 2007
    Location
    The Great State of Texas
    Posts
    205

    Re: Existing txt File

    Holy **** I got it, my mistake. I also apologize for taking my time writing this post and not seeing the "File Handling" Post a few below mine that was also relevant.

    I used this and it took it for some odd reason this time:
    Code:
       If File.Exists(CustomerFile) Then
                MessageBox.Show("File IS THERE!!")
            Else
                MessageBox.Show("FILE IS GONE")
            End If
    Abrium
    Asking the beginners questions so you don't have to!
    If by chance hell actually froze over and I some how helped you... Please rate.

  3. #3
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: Existing txt File

    The File class is located in the System.IO namespace. Usually, you would have to call it by it's full name, eg:
    Code:
    If System.IO.File.Exists(CustomerFile) Then ...
    But, to shorten things, you can use so called Imports. You can import namespaces, and you then no longer have to use the full names, but you can use 'abbreviations', like so:
    Code:
    'Top of code:
    Imports System.IO
    
    '...
    
    'Somewhere in your code:
    If File.Exists(CustomerFile) Then ...
    If you did not import the namespace, VB will tell you it doesn't know the File class. You must have read over something explaining or at least telling you about importing the System.IO namespace.


    The same is true (I think!) btw for the FileSystem class you tried the first time (although I'm not sure if it's also in System.IO or in some other namespace).

  4. #4
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Re: Existing txt File

    Please remember to mark your thread resolved.
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Existing txt File

    Quote Originally Posted by Abrium View Post
    MSDN told me to use FileSystem.FileExists(file) - VS would not take this
    That would be My.Computer.FileSystem.FileExists.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width