How can I loop through a folder getting each file listed and when its date/time?
+4
A:
Use DirectoryInfo.GetFiles() and extract the data (Name, CreationTime, etc.) from the FileInfo class.
I've pasted some code from the MSDN page here.
Imports System
Imports System.IO
Public Class GetFilesTest
Public Shared Sub Main()
' Make a reference to a directory.
Dim di As New DirectoryInfo("c:\")
' Get a reference to each file in that directory.
Dim fiArr As FileInfo() = di.GetFiles()
' Display the names of the files.
Dim fri As FileInfo
For Each fri In fiArr
Console.WriteLine(fri.Name)
Next fri
End Sub 'Main
End Class 'GetFilesTest
micahtan
2010-02-07 05:58:52
how do I get the DateTime of fri? And copy it to another folder?
bochur1
2010-02-07 06:29:37
fri.CreationTime will give you the date/time when the file was created. To copy the file to another directory you can use the shared Copy method on the File class - File.Copy(fri.FullName, "C:\SomeDir\File.exe"
lee-m
2010-02-07 12:17:34