Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    Regular Coder najkiie's Avatar
    Join Date
    Oct 2008
    Location
    Sweden
    Posts
    103
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Save a file, need help with filename... plz help?

    Hey, im trying to make a program that saves a textfile in a special folder. I can do that, but if i want to save lets say "text.txt" in "C:/Blah/text.txt" it will save it correctly. But if i want to save 2 files it will just overwrite the first one... how do i make it create a new text file like "text2.text" ??


    please help me

    -Nike

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,801
    Thanks
    160
    Thanked 2,216 Times in 2,203 Posts
    Blog Entries
    1
    I'd give a different name . Seriously, which is your programming language?
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    Regular Coder najkiie's Avatar
    Join Date
    Oct 2008
    Location
    Sweden
    Posts
    103
    Thanks
    7
    Thanked 0 Times in 0 Posts
    yeah i know i could just give it a new name... but im not using a "savefiledialog" it saves automatically in the background.

    im using Visual Basic Express 2008 for this project.

    Thnx for responding

  • #4
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    Well how are you creating and saving the file? At some point you must be specifying the filename. Just specify a different one for the second file.

    If you are unsure, post some of the code that is relevant to your file creation and saving and we can help you with it.
    OracleGuy

  • #5
    Regular Coder najkiie's Avatar
    Join Date
    Oct 2008
    Location
    Sweden
    Posts
    103
    Thanks
    7
    Thanked 0 Times in 0 Posts
    If System.IO.File.Exists("C:/Habbop/user.txt") Then
    Dim SaveP As New System.IO.StreamWriter("C:/Habbop/user2.txt")
    SaveP.Write(textbox1.text + textbox3.text)
    SaveP.Close()

    Else
    Dim SaveU As New System.IO.StreamWriter("C:/Habbop/user.txt")
    SaveP.Write(textbox1.text + textbox3.text)
    SaveU.Close()
    End If


    I don't know if you understand me :P The user will click a button, and something will happen, and at the same time it saves a textfile in the background without the user knowing it. I wan't it to create a new file each time i press that button, and i don't want it to overwrite the orginal one. That folder will probably have over 25-30 textfiles. I don't want to code that!!!

    The code im using now is just temporary, now he/she can at least save 2 files...

    Got it? -Nike

  • #6
    Master Coder
    Join Date
    Apr 2003
    Location
    in my house
    Posts
    5,211
    Thanks
    39
    Thanked 201 Times in 197 Posts
    will these 25-30 files all be totally different from each other or identical? I am thinking that you could save to the same single file but instead of whatsit, erm, oh yeh truncating it, you could write to it beneath whatever is still there in it.

    Otherwise (if you really need many files), you could store them with a numeric name. Then when a new one is being saved, the processing could include a dir look-up to get the latest number in the existing filenames. Increment that and give it to the new file for its name.


    bazz
    "The day you stop learning is the day you become obsolete"! - my late Dad.

    Why do some people say "I don't know for sure"? If they don't know for sure then, they don't know!
    Useful MySQL resource
    Useful MySQL link

  • Users who have thanked bazz for this post:

    najkiie (11-17-2008)

  • #7
    Regular Coder najkiie's Avatar
    Join Date
    Oct 2008
    Location
    Sweden
    Posts
    103
    Thanks
    7
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by bazz View Post
    Otherwise (if you really need many files), you could store them with a numeric name. Then when a new one is being saved, the processing could include a dir look-up to get the latest number in the existing filenames. Increment that and give it to the new file for its name.
    That is exactly what i want to do! but instead of saving it as 1.text, 2.text and so on... could it be name1.txt, name2.txt?

    Anyways, could you give me a code example of it? Thanks.

  • #8
    Master Coder
    Join Date
    Apr 2003
    Location
    in my house
    Posts
    5,211
    Thanks
    39
    Thanked 201 Times in 197 Posts
    well I think it is now time to have this thread moved into the forum gor the language that you are using.
    (do not cross-post or you'll make a mod have to post cross )

    Oh yeh, have you worked out how you are going to identify each file for when you need to retrieve the info contained within it? no point having a load of files if you can't relate their filenames or content with anything?


    hth
    bazz
    "The day you stop learning is the day you become obsolete"! - my late Dad.

    Why do some people say "I don't know for sure"? If they don't know for sure then, they don't know!
    Useful MySQL resource
    Useful MySQL link

  • #9
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    Quote Originally Posted by bazz View Post
    well I think it is now time to have this thread moved into the forum gor the language that you are using.
    (do not cross-post or you'll make a mod have to post cross )
    This is the right forum for VB.NET.

    As to the OP's question, the filename you specify here:
    Code:
    Dim SaveU As New System.IO.StreamWriter("C:/Habbop/user.txt")
    Doesn't have to be a string literal, you can build the filename dynamically with a variable and pass the variable as the filename.
    OracleGuy

  • #10
    Regular Coder najkiie's Avatar
    Join Date
    Oct 2008
    Location
    Sweden
    Posts
    103
    Thanks
    7
    Thanked 0 Times in 0 Posts
    wops, sry for the double post o.O
    Last edited by najkiie; 11-17-2008 at 07:12 PM.

  • #11
    Regular Coder najkiie's Avatar
    Join Date
    Oct 2008
    Location
    Sweden
    Posts
    103
    Thanks
    7
    Thanked 0 Times in 0 Posts
    thanks oracleguy, one question...

    Quote Originally Posted by oracleguy View Post
    you can build the filename dynamically with a variable and pass the variable as the filename.
    What exactly do you mean with that?

    If i forgot to tell you guys before, im a beginner, so please don't get mad on me or anything becouse of all my questions?


  •  

    Posting Permissions

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