VBA - List last accessed & last modified date (including subfolders)

Carterland

New Member
Joined
Jan 19, 2021
Messages
16
Office Version
  1. 365
Platform
  1. Windows
Hi All,

I've looked around but I can't seem to find a working code that does ALL of the bits I need. I have seen some with parts of it and others that seem to have it all but for whatever reason (likely my fault) I cant get it to work.

So I'm looking for a VBA code that will look through a file path, then look in all subfolders within the file path and return the details required for a file within each of the subfolders named 'LWDB'.

So the folder structure is:

Main folder path followed by 5 subfolders named: 1, 2, 3, 4, 5

Within each of those folders there is a file names LWDB

I need the code to return the details for each of those 5 LWDB files.

I hope that makes sense. I have attached an image below to give you some idea. The subfolder numbers won't changes so Column A doesn't need amending in any way.

Thanks in advance :)
 

Attachments

  • Capture.PNG
    Capture.PNG
    21.8 KB · Views: 40
Try this:

Change the initial folder on this line.
sPath = "C:\trabajo\" 'initial path folder

Enabling the microsoft scripting reference in the tools option

In my tests I must Set att = CreateObject("Scripting.FileSystemObject"), So let's move on.

VBA Code:
Sub FilesDates()
  Dim sPath As String, subFolder As String, sFile As String
  Dim att As Scripting.FileSystemObject
  Dim i As Long
  Set att = CreateObject("Scripting.FileSystemObject")
  sPath = "C:\trabajo\"   'initial path folder
  '
  For i = 1 To 5
    subFolder = sPath & i & "\" & "Log" & "\"
    sFile = Dir(subFolder & "LWDB*")
    If sFile <> "" Then
      Cells(i + 1, "B") = sFile
      Cells(i + 1, "C") = att.GetFile(subFolder & sFile).DateCreated
      Cells(i + 1, "D") = att.GetFile(subFolder & sFile).DateLastAccessed
      Cells(i + 1, "E") = att.GetFile(subFolder & sFile).DateLastModified
    End If
  Next
End Sub

So you should have a folder structure as follows:

View attachment 40009
Hello mate, apologies for the late response. This worked perfectly so thanks very much, really appreciate the time and effort.

:)
 
Upvote 0

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.

Forum statistics

Threads
1,223,247
Messages
6,171,007
Members
452,374
Latest member
keccles

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top