Excel VBA using FileSystemObject to list file last date modified -


this first time asking question i'm following protocol. in reference "get list of subdirs in vba" get list of subdirs in vba.

i found brett's example #1 - using filescriptingobject helpful. there's 1 more data element (datelastmodified) need in results. tried modify code keep getting invalid qualifier error. here code modifications made:

  1. range("a1:c1") = array("file name", "path", "date last modified").
  2. do while loop added => cells(i, 3) = myfile.datelastmodified.

will appreciate include "date last modified".

santosh here complete code comments indicating modifications.

public arr() string public counter long  sub loopthroughfilepaths() dim myarr dim long dim j long dim myfile string const strpath string = "c:\temp\" myarr = getsubfolders(strpath) application.screenupdating = false 'range("a1:b1") = array("text file", "path")' <= orig code range("a1:c1") = array("text file", "path", "date last modified") ' <= modified code     j = lbound(arr) ubound(arr)         myfile = dir(myarr(j) & "\*.txt")         while len(myfile) <> 0         = + 1             cells(i, 1) = myfile             cells(i, 2) = myarr(j)             cells(i, 3) = myfile.datelastmodified ' <= added modify code             myfile = dir         loop     next j application.screenupdating = true end sub  function getsubfolders(rootpath string) dim fso object dim fld object dim sf object dim myarr  set fso = createobject("scripting.filesystemobject") set fld = fso.getfolder(rootpath) each sf in fld.subfolders     counter = counter + 1     redim preserve arr(counter)     arr(counter) = sf.path     myarr = getsubfolders(sf.path) next getsubfolders = arr set sf = nothing set fld = nothing set fso = nothing end function   

try code :

sub listfilesinfolder()      dim fso scripting.filesystemobject     dim sourcefolder scripting.folder     dim fileitem scripting.file      sourcefoldername = "c:\users\santosh"      set fso = new scripting.filesystemobject     set sourcefolder = fso.getfolder(sourcefoldername)      range("a1:c1") = array("text file", "path", "date last modified")      = 2     each fileitem in sourcefolder.files         cells(i, 1) = fileitem.name         cells(i, 2) = fileitem         cells(i, 3) = fileitem.datelastmodified         = + 1     next fileitem      set fso = nothing  end sub 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -