Answered by:
Creating folders with current time as the folder name

Question
-
Hello all. I have been trying to create folders for database backup purposes. These folders were to be based on the current date and time as the name of the folder. This is the code I came up with:
Sub Backup()
Try
Dim FolderName As String
Dim PathCreate As String
Dim BackupDate As String
Dim ActionDate As Date
Dim Datea As New DateTimePicker
Datea.Format = DateTimePickerFormat.Short
Datea.Value = Date.Today
ActionDate = Datea.Value.ToString
BackupDate = Datea.Value.ToString
Directory.CreateDirectory("C:/Database Backup")
PathCreate = "C:/Database Backup/Backup - " + BackupDate
Directory.CreateDirectory(PathCreate)
File.Copy("C:/Users/Honourable Majiwa_2/Desktop/stadiadatabase.mdb", +PathCreate + "/stadiadatabase.mdb")
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "Backup Error!")
End Try
End SubHowever, I experience an error when the code is executed. The message given is:
"The given path's format is not supported!"
What could be the problem? Any help given would be most appreciated. Thank you in advance
Monday, October 18, 2010 11:58 AM
Answers
-
Instead of following lineBackupDate = Datea.Value.ToString
you can use this and try
BackupDate = Datea.Value.ToString("yyyy-MM-dd hh-mm-ss")
Thanks and Regards, Bharath S.- Marked as answer by Cescontita Tuesday, October 19, 2010 9:05 AM
Monday, October 18, 2010 1:19 PM
All replies
-
Hi,
check the value of your BackupDate variable. It mustn`t contain the following chars: /\:#?"<>|
Hannes
If you have got questions about this, just ask.
Mark the thread as answered if the answer helps you. This helps others who have the same problem !
C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/Monday, October 18, 2010 12:06 PM -
Instead of following lineBackupDate = Datea.Value.ToString
you can use this and try
BackupDate = Datea.Value.ToString("yyyy-MM-dd hh-mm-ss")
Thanks and Regards, Bharath S.- Marked as answer by Cescontita Tuesday, October 19, 2010 9:05 AM
Monday, October 18, 2010 1:19 PM -
Please note that the directory separator character is \ on Windows. Also, the string concatenation operator is &
HTH,
Andrew
- Proposed as answer by Heslacher Monday, October 18, 2010 3:27 PM
Monday, October 18, 2010 3:01 PM -
Please note that the directory separator character is \ on Windows.
Hannes
If you have got questions about this, just ask.
Mark the thread as answered if the answer helps you. This helps others who have the same problem !
C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/Monday, October 18, 2010 3:27 PM -
Hi Cescontita,
check this for more Path information:
http://msdn.microsoft.com/en-us/library/system.io.path.aspx
there is a methode getinvalidfilenamechars
http://msdn.microsoft.com/en-us/library/system.io.path.getinvalidfilenamechars.aspx
Please 'Mark as Answer' if I helped. This helps others who have the same problem!Tuesday, October 19, 2010 5:04 AM -
I knew that the backslash was the problem. I had earlier tried declaring a variable as a DateTimePicker control and set the format to Short. This however did not solve my problem.Tuesday, October 19, 2010 9:03 AM
-
I noticed that it instead created sub folders with the month and year as their names.Tuesday, October 19, 2010 9:05 AM
-
Thank you Bharath. I also tweaked the code you gave me a bit and this is the code as I actually visualised it:
BackupDate = Datea.ToString("dd-MM-yyyy hh.mm")
So this gave me the folder with the actual date and time.
Your insight was very helpful.
Tuesday, October 19, 2010 9:43 AM