CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Apr 2004
    Posts
    158

    [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.

  2. #2
    Join Date
    Apr 2004
    Posts
    158

    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.

  3. #3
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    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
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  4. #4
    Join Date
    Apr 2004
    Posts
    158

    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.

  5. #5
    Join Date
    Apr 2004
    Posts
    158

    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.

  6. #6
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    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.

  7. #7
    Join Date
    Apr 2004
    Posts
    158

    Re: When was text file created?

    Quote Originally Posted by DataMiser View Post
    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.

  8. #8
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    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.

  9. #9
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: When was text file created?

    Quote Originally Posted by dajunka View Post
    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.

  10. #10
    Join Date
    Apr 2004
    Posts
    158

    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
  •  





Click Here to Expand Forum to Full Width

Featured