I want to display the date a text file was created and modified could anyone point me in the right direction? Visual studio 2008
Thank you :wave:
Printable View
I want to display the date a text file was created and modified could anyone point me in the right direction? Visual studio 2008
Thank you :wave:
By searching I found these solutions but I cannot get them to work.
File.GetLastWriteTime(fileName)
and
File.GetCreationTime(fileName)
Any idea's?
MSDN?
http://msdn.microsoft.com/en-us/libr...ationtime.aspxCode:Imports System
Imports System.IO
Imports System.Text
Public Class Test
Public Shared Sub Main()
Try
' Get the creation time of a well-known directory.
Dim dt As DateTime = Directory.GetCreationTime(Environment.CurrentDirectory)
' Give feedback to the user.
If (DateTime.Now.Subtract(dt).TotalDays > 364) Then
Console.WriteLine("This directory is over a year old.")
ElseIf (DateTime.Now.Subtract(dt).TotalDays > 30) Then
Console.WriteLine("This directory is over a month old.")
ElseIf (DateTime.Now.Subtract(dt).TotalDays <= 1) Then
Console.WriteLine("This directory is less than a day old.")
Else
Console.WriteLine("This directory was created on {0}.", dt)
End If
Catch e As Exception
Console.WriteLine("The process failed: {0}", e.ToString())
End Try
End Sub
End Class
Sorry, but that didn't work.
Sorry, but that didn't work.
It seems this is one of those many things that VB.net is not very good at. In VB6 I use to do it like so...
Code:Requires reference to Microsoft Scripting Runtime
Dim fso As FileSystemObject
Set fso = New FileSystemObject
TempDate = Left(fso.GetFile(UserString).DateLastModified, 6) & Mid(fso.GetFile(UserString).DateLastModified, 9, 2)
do your code have enough permissions? If not, you will not find the file at all...Quote:
I cannot get them to work
What did you get with the code dglienna posted?
If I remember correctly there is a fileinfo property that should give you want you need.
btw FSO is not a good way to do this in VB6 either. This is used by a lot of people it seems but is really meant for VBScripting. VB6 has much better ways to handle files than using FSO
Your right DataMiser, and I did find it, but the examples I found all had errors of one kind or another.
On the other hand your answer worked perfectly, thank you very much, I can now proceed with my little program. :wave: