Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. VB 2008 Express, Get Modified date stamp

VB 2008 Express, Get Modified date stamp

Scheduled Pinned Locked Moved Visual Basic
help
14 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nhsal69
    wrote on last edited by
    #1

    Hi there, I'm pretty new to this but what I'm after is a method of getting the Last modified date from a file, then renaming the file to that data/time stamp.. If there are any duplicates then appending _1, _2 etc to them.... I've been looking for the correct file.getX and have found the file.getattributes, for hidden /readonly etc.. but can't find the correct one for file Properties, specifically modified time. Can anyone help... Thanks

    D 1 Reply Last reply
    0
    • N nhsal69

      Hi there, I'm pretty new to this but what I'm after is a method of getting the Last modified date from a file, then renaming the file to that data/time stamp.. If there are any duplicates then appending _1, _2 etc to them.... I've been looking for the correct file.getX and have found the file.getattributes, for hidden /readonly etc.. but can't find the correct one for file Properties, specifically modified time. Can anyone help... Thanks

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      You're looking for the FileInfo[^] class, which has a LastWriteTime property.

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007, 2008
      But no longer in 2009...

      N 2 Replies Last reply
      0
      • D Dave Kreskowiak

        You're looking for the FileInfo[^] class, which has a LastWriteTime property.

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007, 2008
        But no longer in 2009...

        N Offline
        N Offline
        nhsal69
        wrote on last edited by
        #3

        Smashing... thanks for that....

        D 1 Reply Last reply
        0
        • N nhsal69

          Smashing... thanks for that....

          D Offline
          D Offline
          DaveAuld
          wrote on last edited by
          #4

          nhsal69 wrote:

          Smashing...

          Not often I hear someone from Scotland using that!

          Dave Don't forget to rate messages!
          Find Me On: Web|Facebook|Twitter|LinkedIn
          Waving? dave.m.auld[at]googlewave.com

          N L 2 Replies Last reply
          0
          • D DaveAuld

            nhsal69 wrote:

            Smashing...

            Not often I hear someone from Scotland using that!

            Dave Don't forget to rate messages!
            Find Me On: Web|Facebook|Twitter|LinkedIn
            Waving? dave.m.auld[at]googlewave.com

            N Offline
            N Offline
            nhsal69
            wrote on last edited by
            #5

            What can I say, I'm diverse :P

            N L 2 Replies Last reply
            0
            • N nhsal69

              What can I say, I'm diverse :P

              N Offline
              N Offline
              nhsal69
              wrote on last edited by
              #6

              Just one more thing... fsi.lastaccesstime, fsi.creationtime all appear to generate day moth year in teh form "23 March 2010" but I need it to include the hours mins and sec.. any ideas?? the example I'm using is: Imports System.IO Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ' Loop through all the immediate subdirectories of C. For Each entry As String In Directory.GetDirectories("C:\temp\test") DisplayFileSystemInfoAttributes(New DirectoryInfo(entry)) Next ' Loop through all the files in C. For Each entry As String In Directory.GetFiles("C:\temp\test") DisplayFileSystemInfoAttributes(New FileInfo(entry)) Next End Sub Sub DisplayFileSystemInfoAttributes(ByVal fsi As IO.FileSystemInfo) ' Assume that this entry is a file. Dim entryType As String = "File" ' Determine if this entry is really a directory. If (fsi.Attributes And FileAttributes.Directory) = FileAttributes.Directory Then entryType = "Directory" End If ' Show this entry's type, name, and creation date. Console.WriteLine("{0} entry {1} was created on {2:D}", _ entryType, fsi.FullName, fsi.LastAccessTime) End Sub End Class Any thoughts?? Thanks

              D W 2 Replies Last reply
              0
              • N nhsal69

                Just one more thing... fsi.lastaccesstime, fsi.creationtime all appear to generate day moth year in teh form "23 March 2010" but I need it to include the hours mins and sec.. any ideas?? the example I'm using is: Imports System.IO Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ' Loop through all the immediate subdirectories of C. For Each entry As String In Directory.GetDirectories("C:\temp\test") DisplayFileSystemInfoAttributes(New DirectoryInfo(entry)) Next ' Loop through all the files in C. For Each entry As String In Directory.GetFiles("C:\temp\test") DisplayFileSystemInfoAttributes(New FileInfo(entry)) Next End Sub Sub DisplayFileSystemInfoAttributes(ByVal fsi As IO.FileSystemInfo) ' Assume that this entry is a file. Dim entryType As String = "File" ' Determine if this entry is really a directory. If (fsi.Attributes And FileAttributes.Directory) = FileAttributes.Directory Then entryType = "Directory" End If ' Show this entry's type, name, and creation date. Console.WriteLine("{0} entry {1} was created on {2:D}", _ entryType, fsi.FullName, fsi.LastAccessTime) End Sub End Class Any thoughts?? Thanks

                D Offline
                D Offline
                Dave Kreskowiak
                wrote on last edited by
                #7

                It DOES return the date and time, but, you have to go a little deeper that just LastWriteTime. LastWriteTime returns just a Date object, but all Date objects also hold a time. You just have to tell it to return that information. Hit "." after fsi.LastAccessTime and you'll see all the properties and methods exposed by the Date object it returns, including Hour, Minute, Second, ToShortTimeString, ToLongTimeString, ToString (where you can provide a custom format string to return the date/time in any format you want)...

                A guide to posting questions on CodeProject[^]
                Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                     2006, 2007, 2008
                But no longer in 2009...

                1 Reply Last reply
                0
                • N nhsal69

                  Just one more thing... fsi.lastaccesstime, fsi.creationtime all appear to generate day moth year in teh form "23 March 2010" but I need it to include the hours mins and sec.. any ideas?? the example I'm using is: Imports System.IO Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ' Loop through all the immediate subdirectories of C. For Each entry As String In Directory.GetDirectories("C:\temp\test") DisplayFileSystemInfoAttributes(New DirectoryInfo(entry)) Next ' Loop through all the files in C. For Each entry As String In Directory.GetFiles("C:\temp\test") DisplayFileSystemInfoAttributes(New FileInfo(entry)) Next End Sub Sub DisplayFileSystemInfoAttributes(ByVal fsi As IO.FileSystemInfo) ' Assume that this entry is a file. Dim entryType As String = "File" ' Determine if this entry is really a directory. If (fsi.Attributes And FileAttributes.Directory) = FileAttributes.Directory Then entryType = "Directory" End If ' Show this entry's type, name, and creation date. Console.WriteLine("{0} entry {1} was created on {2:D}", _ entryType, fsi.FullName, fsi.LastAccessTime) End Sub End Class Any thoughts?? Thanks

                  W Offline
                  W Offline
                  Wayne Gaylard
                  wrote on last edited by
                  #8

                  nhsal69 wrote:

                  Console.WriteLine("{0} entry {1} was created on {2: D}", _ entryType, fsi.FullName, fsi.LastAccessTime)

                  If you just leave out the format symbol on your date, using {2} instead of {2: D} then you will get the time component as well.

                  N 1 Reply Last reply
                  0
                  • W Wayne Gaylard

                    nhsal69 wrote:

                    Console.WriteLine("{0} entry {1} was created on {2: D}", _ entryType, fsi.FullName, fsi.LastAccessTime)

                    If you just leave out the format symbol on your date, using {2} instead of {2: D} then you will get the time component as well.

                    N Offline
                    N Offline
                    nhsal69
                    wrote on last edited by
                    #9

                    Ahh, thanks for that..

                    1 Reply Last reply
                    0
                    • D DaveAuld

                      nhsal69 wrote:

                      Smashing...

                      Not often I hear someone from Scotland using that!

                      Dave Don't forget to rate messages!
                      Find Me On: Web|Facebook|Twitter|LinkedIn
                      Waving? dave.m.auld[at]googlewave.com

                      L Offline
                      L Offline
                      Luc Pattyn
                      wrote on last edited by
                      #10

                      Andy Murray does. :)

                      Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


                      Getting an article published on CodeProject now is hard and not sufficiently rewarded.


                      N 1 Reply Last reply
                      0
                      • N nhsal69

                        What can I say, I'm diverse :P

                        L Offline
                        L Offline
                        Luc Pattyn
                        wrote on last edited by
                        #11

                        nhsal69 wrote:

                        I'm diverse

                        which is good. Now reading a book on VB.NET would give you more depth on .NET programming. :)

                        Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


                        Getting an article published on CodeProject now is hard and not sufficiently rewarded.


                        1 Reply Last reply
                        0
                        • L Luc Pattyn

                          Andy Murray does. :)

                          Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


                          Getting an article published on CodeProject now is hard and not sufficiently rewarded.


                          N Offline
                          N Offline
                          nhsal69
                          wrote on last edited by
                          #12

                          Luc Pattyn wrote:

                          Andy Murray does.

                          Yeah, he is renowned for his ability to code while serving.. all that shouting between points is critic of his SQL and systemfileinfo coding I need to listen more closely next game to get hints and tips...

                          1 Reply Last reply
                          0
                          • D Dave Kreskowiak

                            You're looking for the FileInfo[^] class, which has a LastWriteTime property.

                            A guide to posting questions on CodeProject[^]
                            Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                                 2006, 2007, 2008
                            But no longer in 2009...

                            N Offline
                            N Offline
                            nhsal69
                            wrote on last edited by
                            #13

                            I now have a piece of code which scans a folder and reset the file names to the exact date and time the file was created.. The only problem is I need the modified time (these are all photos, and the modified time is the time the photo was taken) ever other time stamp has been changed when the files were copied from camera to phone etc. So FileInfo gives you: CreationTime LastAccessTime LastWriteTime as well as various other bits and bobs, but no Modified time. I can see it in the jpg files properties, so it must be getabe?? Any ideas??

                            D 1 Reply Last reply
                            0
                            • N nhsal69

                              I now have a piece of code which scans a folder and reset the file names to the exact date and time the file was created.. The only problem is I need the modified time (these are all photos, and the modified time is the time the photo was taken) ever other time stamp has been changed when the files were copied from camera to phone etc. So FileInfo gives you: CreationTime LastAccessTime LastWriteTime as well as various other bits and bobs, but no Modified time. I can see it in the jpg files properties, so it must be getabe?? Any ideas??

                              D Offline
                              D Offline
                              Dave Kreskowiak
                              wrote on last edited by
                              #14

                              LastWriteTime IS the "Last Modified Time" in NTFS. If you're talking about getting a time out of the metadata in the picture file itself, then these methods will do nothing for you. You need to get the properties out of the JPG. Google for "jpeg metadata vb.net[^]".

                              A guide to posting questions on CodeProject[^]
                              Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                                   2006, 2007, 2008
                              But no longer in 2009...

                              1 Reply Last reply
                              0
                              Reply
                              • Reply as topic
                              Log in to reply
                              • Oldest to Newest
                              • Newest to Oldest
                              • Most Votes


                              • Login

                              • Don't have an account? Register

                              • Login or register to search.
                              • First post
                                Last post
                              0
                              • Categories
                              • Recent
                              • Tags
                              • Popular
                              • World
                              • Users
                              • Groups