...

View Full Version : Save a file, need help with filename... plz help?



najkiie
11-15-2008, 05:05 PM
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

abduraooft
11-15-2008, 05:11 PM
I'd give a different name :). Seriously, which is your programming language?

najkiie
11-15-2008, 08:11 PM
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 :)

oracleguy
11-15-2008, 08:22 PM
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.

najkiie
11-16-2008, 09:58 AM
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

bazz
11-17-2008, 01:49 AM
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

najkiie
11-17-2008, 06:54 PM
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! :D 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.

bazz
11-17-2008, 07:40 PM
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

oracleguy
11-17-2008, 08:05 PM
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:

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.

najkiie
11-17-2008, 08:05 PM
wops, sry for the double post o.O

najkiie
11-17-2008, 08:11 PM
thanks oracleguy, one question...


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? :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum