Results 1 to 11 of 11

Thread: check if a file exits etc...

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2003
    Posts
    91

    check if a file exits etc...

    Okay, i need 2 make a list of winners. First, i would like to check if a certain file, (lstwinners.txt) exists. If it exists, it would add a certain string to the end of it. If it doesn't it would create it then add a string to the end. Please help!

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Dec 2003
    Posts
    91
    bump - please help me!

  3. #3
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    With all respect, do a little reading. This is basic file i/o and is covered in books, MSDN, google searches etc.

    But to help out, why don't you just open the file in append mode and then write to it?

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Dec 2003
    Posts
    91
    Originally posted by Mike Hildner
    With all respect, do a little reading. This is basic file i/o and is covered in books, MSDN, google searches etc.

    But to help out, why don't you just open the file in append mode and then write to it?
    i have a crappy textbook that doesnt tell me ****, and i would appreciate it if you could give me the exact code.. thanks

  5. #5
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    Well, that might be cheating. MSDN is a great resource, and it's on your machine/the web. Search for "File.Open Method", try out some examples, and if you still have troubles post the code you've tried and you'll get help.

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Dec 2003
    Posts
    91
    cheating? lol this is a program im making for fun! its for a game im making - a high score list if you will. please help. thanks

  7. #7
    New Member
    Join Date
    Dec 2003
    Posts
    12

    Hope to help...

    Dim strPath As String = "C:\d.txt"
    Dim SW As StreamWriter
    Dim FS As FileStream

    If File.Exists(strPath) = True Then
    MsgBox("True")
    FS = New FileStream(strPath, FileMode.Open)
    SW = New StreamWriter(FS)
    SW.WriteLine("True")
    Else
    MsgBox("False")
    FS = New FileStream(strPath, FileMode.Create)
    SW = New StreamWriter(FS)
    SW.WriteLine("False")
    End If

    SW.Close()
    FS.Close()
    Things go better with rock

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Dec 2003
    Posts
    91
    works great xcept if it doesnt exist, i want it to create it AND write a line to it...

  9. #9
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    VB Code:
    1. Dim sw As StreamWriter = New StreamWriter("c:\temp\myfile.txt", True)
    2.         sw.WriteLine("This is a simple example - MSDN is your friend!")
    3.         sw.Close()

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Dec 2003
    Posts
    91
    how do i load items from a txt file into a listbox? then im done!

  11. #11
    New Member
    Join Date
    Dec 2003
    Posts
    12
    Dim strPath As String = "C:\Items.txt"

    Dim SR As StreamReader
    Dim FS As FileStream
    FS = New FileStream(strPath, FileMode.Open)
    SR = New StreamReader(FS)

    Dim itm As Object
    itm = SR.ReadLine()
    While Not itm = Nothing
    Listbox1.Items.Add(itm)
    itm = SR.ReadLine()
    End While

    SR.Close()
    FS.Close()
    Things go better with rock

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