|
-
January 11th, 2011, 03:39 AM
#1
[RESOLVED] When was text file created?
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
Last edited by dajunka; January 11th, 2011 at 04:26 AM.
I use VB.Net 2008 in all my wash, for those whiter whites.
-
January 12th, 2011, 12:33 AM
#2
Re: When was text file created?
By searching I found these solutions but I cannot get them to work.
File.GetLastWriteTime(fileName)
and
File.GetCreationTime(fileName)
Any idea's?
I use VB.Net 2008 in all my wash, for those whiter whites.
-
January 12th, 2011, 05:49 AM
#3
Re: When was text file created?
MSDN?
Code:
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
http://msdn.microsoft.com/en-us/libr...ationtime.aspx
-
January 12th, 2011, 09:38 AM
#4
Re: When was text file created?
Sorry, but that didn't work.
I use VB.Net 2008 in all my wash, for those whiter whites.
-
January 12th, 2011, 10:40 AM
#5
Re: When was text file created?
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)
I use VB.Net 2008 in all my wash, for those whiter whites.
-
January 12th, 2011, 11:05 AM
#6
Re: When was text file created?
I cannot get them to work
do your code have enough permissions? If not, you will not find the file at all...
What did you get with the code dglienna posted?
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
-
January 12th, 2011, 11:43 AM
#7
Re: When was text file created?
 Originally Posted by DataMiser
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
Can you by any chance remember how to use "fileinfo"? I have tried it a few ways without result.
That VB6 code I got from these forums, years back, and it worked well for me at the time.
I use VB.Net 2008 in all my wash, for those whiter whites.
-
January 12th, 2011, 01:26 PM
#8
Re: When was text file created?
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
Always use [code][/code] tags when posting code.
-
January 12th, 2011, 04:19 PM
#9
Re: When was text file created?
 Originally Posted by dajunka
Can you by any chance remember how to use "fileinfo"? I have tried it a few ways without result.
That VB6 code I got from these forums, years back, and it worked well for me at the time. 
It is pretty simple.
Code:
Dim F as new System.IO.FileInfo("\MyFile.Txt")
msgbox (F.CreationTime)
A simple search of your online help should have provided this for you
Always use [code][/code] tags when posting code.
-
January 13th, 2011, 03:51 AM
#10
Re: When was text file created? (resolved)
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.
I use VB.Net 2008 in all my wash, for those whiter whites.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|