Have PDFs in folders. Need to record the names and locations in Excel -


don't see questions similar looking for.

i have 20k+ pdfs stored in various locations on c drive. don't have complete list of available or when created.

what looking find names, size , dates file created. these need recorded in excel spreadsheet

note: of pdfs buried 6 or 7 folders deep, while 1 folder deep.

can suggest way of automatically it?

i have tried using code*:

sub listallfiles()     dim fs filesearch, ws worksheet, long     dim r long     set fs = application.filesearch     fs         .searchsubfolders = true '         .filetype = msofiletypeallfiles 'can modify excel files eg msofiletypeexcelworkbooks         .lookin = "h:\my desktop"         if .execute > 0             set ws = worksheets.add             r = 1             = 1 .foundfiles.count                 if right(.foundfiles(i), 3) = ".pdf" or right(.foundfiles(i), 3) = ".tif"                     ws.cells(r, 1) = .foundfiles(i)                     r = r + 1                 end if             next         else              msgbox "no files found"         end if     end end sub 

however, seems return issue in 4th line - application.filesearch

i have tried this*, works well, doesn't go folders:

sub listallfile()      dim objfso object     dim objfolder object     dim objfile object     dim ws worksheet      set objfso = createobject("scripting.filesystemobject")     set ws = worksheets.add       'get folder object associated directory     set objfolder = objfso.getfolder("h:\my desktop")     ws.cells(1, 1).value = "the files found in " & objfolder.name & " are:"       'loop through files collection     each objfile in objfolder.files         if ucase$(right$(objfile.name, 4)) = ".pdf"             ws.cells(ws.usedrange.rows.count + 1, 1).value = replace$(ucase$(objfile.name), ".pdf", "")         end if      next       'clean up!     set objfolder = nothing     set objfile = nothing     set objfso = nothing  end sub 

any gratefully appreciated.

  • these codes found on net

maybe help

the main function imports output dos command: dir c:\*.pdf /s | find "pdf"


public sub listfiletypes(optional byval root string = "c:\*.", _                          optional byval ext string = "pdf")      const max_size  long = 17    'max space reserved file sizes      dim long, maxrow long, maxcol long, finfo string, ws worksheet     dim arrlines variant, s string, pat string, midsp long      application.screenupdating = false     set ws = activesheet     ws.cells.delete     s = createobject("wscript.shell").exec( _             "%comspec% /c dir """ & root & ext & """  /s | find """ & ext & """" _         ).stdout.readall     'application.wait + timevalue("0:00:01")    'built-in replacement "sleep"     if len(s) > 0         = max_size 2 step -1             s = replace(s, space(i), vbtab)         'replace space sets tabs         next         arrlines = split(s, vbcrlf)         maxrow = ubound(arrlines, 1)         ws             .cells(1, 1).value2 = root & ext             = 2 maxrow + 2                 if len(arrlines(i - 2)) > 0                     maxcol = ubound(split(arrlines(i - 2), vbtab))                     if maxcol > 0                         .range( _                                 .cells(i, 1), _                                 .cells(i, maxcol + 1)) = split(arrlines(i - 2), vbtab)                         'split file size name                         finfo = .cells(i, maxcol + 1).value2                         midsp = instr(1, finfo, " ")                         .cells(i, maxcol + 1).value2 = mid(finfo, 1, midsp)                         .cells(i, maxcol + 2).value2 = mid(finfo, midsp)                     end if                 end if             next             .usedrange.columns.autofit             = 1 3                 .columns(i).entirecolumn.columnwidth = .columns(i).columnwidth + 5             next         end     end if     application.screenupdating = true end sub 

this how can call it:


public sub testfiletypes()      listfiletypes "c:\*", "pdf"     'or: listfiletypes "c:\temp\*", "pdf"  end sub 

it might take while if have many, generate list similar (per drive)

enter image description here


Comments

Popular posts from this blog

java - Andrioid studio start fail: Fatal error initializing 'null' -

android - Gradle sync Error:Configuration with name 'default' not found -

StringGrid issue in Delphi XE8 firemonkey mobile app -