New File Creation

S

steve_comcast2007

I have and issue with if you already have a filename created how can i
get it to check and make
sure that if a file name is already created it will sequence in the
correct order.

Dim txtFile As New FileInfo(strTempFile)
If txtFile.Exists Then
stream = New FileStream(strTempFile,
FileMode.CreateNew)
End If


When i call this check it will not create a new filename and sequence
however it will tell me that the file is already there...how can I
create a newfile with an incremented sequence.

Now i know there is no code for the file sequence which works jsut
find. However I am asking if anyone has an idea as to why when i call
the CreateNew File it will not create a new file.
 
P

Patrice

I had a hard time to understand what you meant. Basically your code doesn't
work because it raises an exception when trying to create the file ?

If this is what you meant this by design. The CreateNew file precisely means
that you want to create a brand new file and fails if the file already
exists. Please check the documentation for this method.

If you meant that you want to create another file, if the file exists,
you'll have to define a new name in strTempFile before being able to create
a brand new file. This could be done :
- using a function that returns a unique temp file name
- or using whatever algorithm best that best fit your need (for example to
use the current year, month day, to create a log file per day) etc...

Finally this is perhaps FileInfo that confuse you (the problem is that you
would have to change the name for the fileinfo object to be able to create a
new file with it ??) . It would be perhaps clearer to do something such as :

If System.IO.File.Exists(strTempFile) Then
strTempFile=GetNewTempFileName()
Stream=New FileStream(strTempFile etc...)

If this is not that either feel free to clarify or perhaps someone else will
catch what you meant...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top