Logo 
Search:

MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

Fiile List From Root Directory

  Asked By: Thelma    Date: Oct 05    Category: MS Office    Views: 768
  

I need to inport a list of files and some attributes from a folder on
my c-drive. I have absolutely no idea how to go about this. I am not
very familiar will all the commands from VBA and am hoping someone
here can help me.

I need to import the file names into column a, the file size into
column b, and the date created into column c.

If someone can tell me what commnds I need in order to import this
information, I can do the rest, I think.

Thank you.

Share: 

 

3 Answers Found

 
Answer #1    Answered By: Olga Allen     Answered On: Oct 05

A couple of points.
Do you want the file  name, or full path name?
You SAID you wanted the date  created.
Are you sure you don't want the date last modified? (there IS a difference)
put this into a module:

'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
Option Explicit
Dim fso, fc, f, File, Files
Dim Folder
Sub GetFiles()
Dim rowcnt
Sheets("Sheet1").Select
Range("A2:Z65000").ClearContents
Set fso = CreateObject("Scripting.FileSystemObject")
'------------------------------
 folder  = "c:\"
'------------------------------
rowcnt = 1
Set fc = fso.getfolder(Folder)
For Each File In fc.Files
rowcnt = rowcnt + 1
Cells(rowcnt, 1) = File.Name
Cells(rowcnt, 2) = File.Path
Cells(rowcnt, 3) = File.Size
Cells(rowcnt, 4) = File.datecreated
Cells(rowcnt, 5) = File.datelastmodified
Next File
End Sub
'oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo

change "Folder = " to the folder you're looking in.
If you want to recursively go through each subfolder, let me know and we can
modify this to be a function that calls itself recursively with the folder
names.

 
Answer #2    Answered By: Botan Suzuki     Answered On: Oct 05

That worked perfectly. I really appreciate it.

 
Answer #3    Answered By: Fahmida Ahmed     Answered On: Oct 05

Actually, there's really only one command you need to remember ... Google.

A Google search immediately pointed me at
http://www.tanguay.info/web/codeExample.php?id=861 which gets all the file
names. You just need to put them into the cells instead of an array.

A more refined Google search might even give you an example that does the
lot.

 
Didn't find what you were looking for? Find more on Fiile List From Root Directory Or get search suggestion and latest updates.




Tagged: