Re: is it to long filename?
When writing VB.NET, dont use Len(), MkDir(), Dir() or legacy VB syntax, use the .NET Framework to your advantage:
Code:
Dim myPath As String = My.Computer.FileSystem.SpecialDirectories.Desktop
Dim myFile As String = "VolvoPenta"
Dim strPath As String = IO.Path.Combine(myPath, String.Join(" ", myFile, Now.ToString("MM-dd-yyyy")))
If Not IO.Directory.Exists(strpath) Then
IO.Directory.CreateDirectory(strPath)
End If
Re: is it to long filename?
It created the folder with the name you gave it... I don't see what the issue is? (other than you shouldn't use MkDir as the others pointed out).
I also wouldn't do this:
Dim strPath As String = IO.Path.Combine(myPath, Now.ToString((myFile) + "MM-dd-yyyy"))
since it passes your my file to the tostring method, which will cause it to be used by the mask, which may cause funky results later. a better approach would be:
Dim strPath As String = IO.Path.Combine(myPath, string.format(myfile +"{0}", Now.ToString("MM-dd-yyyy")))
I'd probably would break it down a bit more so that all I'm passing to the combine method are just the items for the pathing, and not functions... but eh...it's a personal preference.
-tg
Re: is it to long filename?
Another point is you jump between the my.computer namespace and the IO namepaces. Pick One since consistency is always better. There is also know point checking if the directory exists since this is already handled for us.
Re: is it to long filename?
Your problem is this:
Now.ToString((myFile) + "MM-dd-yyyy"))
as this is formatting Now to "VolvoPentaMM-dd-yyyy" ... so use this instead:
myFile & Now.ToString("MM-dd-yyyy"))
Kris
Re: is it to long filename?
Quote:
Originally Posted by
i00
Your problem is this:
Now.ToString((myFile) + "MM-dd-yyyy"))
as this is formatting Now to "VolvoPentaMM-dd-yyyy" ...
Believe it or nnot, it will still work... the date portion will actually format out to the date it should. But it should be noted that ANY part of the text that is in that string WILL be formatted... so the 'n' in Penta will come out with the month in it.
-tg
Re: is it to long filename?
Quote:
Originally Posted by
techgnome
Believe it or nnot, it will still work... the date portion will actually format out to the date it should. But it should be noted that ANY part of the text that is in that string WILL be formatted... so the 'n' in Penta will come out with the month in it.
-tg
I know that you "can" put other things in the formatting section that are not number / date related ... but IMHO this is REALLY, REALLY bad practice!
Kris
Re: is it to long filename?
Quote:
Originally Posted by
i00
I know that you "can" put other things in the formatting section that are not number / date related ... but IMHO this is REALLY, REALLY bad practice!
Kris
hehehe, agreed. like shooting my foot. I CAN do so but it would be a really bad idea.
-tg