VB 2008 Express, Get Modified date stamp
-
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
-
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
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... -
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... -
-
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 -
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?? ThanksIt 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... -
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?? Thanksnhsal69 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.
-
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.
-
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.
-
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.
-
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.
-
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...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??
-
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??
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...