[Help]Geting Date Modified last[Solved]

Posts 1–11 of 11 · Page 1 of 1
[Help]Geting Date Modified last[Solved]
hmm could someone help me get the last date and time that any given file has been modified last? pretty much i wanna make a function in my app to detect if its file has been edited between run times aka from an outside source any help would be amazing thanks guys
First, go Project> (projectname) Properties > Settings and add a new setting called "closed".

Then:
Code:
    Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
        My.Settings.closed = Date.Now
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        My.Settings.closed = Date.Now
    End Sub
Should work.
ok so that is helpful but what if i want to grab the the date modified from any file like say "C:\file.dll" or osmething along those lines?
Quote Originally Posted by Lolland View Post
First, go Project> (projectname) Properties > Settings and add a new setting called "closed".

Then:
Code:
    Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
        My.Settings.closed = Date.Now
My.Settings.Save()

    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        My.Settings.closed = Date.Now
Code:
My.Settings.Save()

     End Sub
Should work.
A little modification :P
Quote Originally Posted by Jason View Post


LOL wtf? How was this even relevant.

Quote Originally Posted by Qizzle15401 View Post
ok so that is helpful but what if i want to grab the the date modified from any file like say "C:\file.dll" or osmething along those lines?
=\

Anyways, let's let the thread die, it's solved already.

Posting furthermore will come with a consequence.
Quote Originally Posted by Lolland View Post




=\

Anyways, let's let the thread die, it's solved already.

Posting furthermore will come with a consequence.
The date a file was modified...how is that relevant to reading the contents of a file, lol.
You can write it to/read it from a file. It'll always be in My.Settings.closed though.

Add this code to your project:
Code:
    Private Function Readfile(ByVal Filename As String)
        Dim Read As String
        Using r As StreamReader = New StreamReader(Filename)
            Read = r.ReadToEnd()
        End Using
        Return Read
    End Function
    Private Sub WriteFile(ByVal FileName As String, ByVal WhatToWrite As String)
        Using w As StreamWriter = New StreamWriter(FileName)
            w.Write(WhatToWrite)
        End Using
    End Sub
It's used like this:
ReadFile:
Code:
MsgBox(Readfile("C:\test.txt"))  'this will msgbox the Contents of C:\test.txt
WriteFile:
Code:
WriteFile("C:\test.txt", My.Settings.closed) 'this will write the contents of My.Settings.closed to C:\test.txt
ok so im not sure what ur why ur telling me how to read the contents of a file? but i figured it out on my own using this code. what i was trying to do was get the time and date the file was last modified not read the contents of the file? but thanks for trying to help me it turns out it was as easy as this guess i should mess around with it alil more before askin for help haha but thanks guys
Code:
Imports System.IO
Public Class Form1
   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Label1.Text = System.IO.File.GetLastAccessTime("C:\mcdbp.log")
  

    End Sub
End Class
Quote Originally Posted by Qizzle15401 View Post
ok so im not sure what ur why ur telling me how to read the contents of a file? but i figured it out on my own using this code. what i was trying to do was get the time and date the file was last modified not read the contents of the file? but thanks for trying to help me it turns out it was as easy as this guess i should mess around with it alil more before askin for help haha but thanks guys
Code:
Imports System.IO
Public Class Form1
   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Label1.Text = System.IO.File.GetLastAccessTime("C:\mcdbp.log")
  

    End Sub
End Class
99% of coding is done this way Good job
Quote Originally Posted by Lolland View Post
You can write it to/read it from a file. It'll always be in My.Settings.closed though.

Add this code to your project:
Code:
    Private Function Readfile(ByVal Filename As String)
        Dim Read As String
        Using r As StreamReader = New StreamReader(Filename)
            Read = r.ReadToEnd()
        End Using
        Return Read
    End Function
    Private Sub WriteFile(ByVal FileName As String, ByVal WhatToWrite As String)
        Using w As StreamWriter = New StreamWriter(FileName)
            w.Write(WhatToWrite)
        End Using
    End Sub
It's used like this:
ReadFile:
Code:
MsgBox(Readfile("C:\test.txt"))  'this will msgbox the Contents of C:\test.txt
WriteFile:
Code:
WriteFile("C:\test.txt", My.Settings.closed) 'this will write the contents of My.Settings.closed to C:\test.txt
LOL wtf? How was this even relevant.

And also, IO.File.WriteAllText and IO.File.ReadAllText are better for reading/writing blocks of text.

This was what it SOUNDED like you wanted

Code:
Private Function GetModifiedDate(ByVal fileLocation As String) As Date
    Return IO.File.GetLastWriteTime(fileLocation)
End Function


And then to use:

Code:
MsgBox(GetModifiedDate("C:\Test\Syntax.txt").ToShortDateString)


That's about it.

EDIT: Didn't see that you'd already found something. Are you sure you want last access? Did you want the last modified value?
Okay, This is solved, leave it alone.
Posts 1–11 of 11 · Page 1 of 1
This thread is closed for replies.

Tags for this Thread

None

Talk with us