How do i create a list of files per directory?

C

Costis

Hello,

i would like to create a representation of the existing files per directory,
so that i can follow up the files i am keeping in the various data
directories i have (not the system).
I Know this information already exists in the system, and it is utilized by
Windows Explorer but i do not know how to access it and import it in Excell
or Access.

Any Help?
Thanks in advance
 
H

Halim

Costis,

You can use Dir function, here is the codes:

Sub DirFiles()
Dim MyDir, i As Integer
MyDir = Dir("C:\*.*")
While MyDir <> ""
i = i + 1
Cells(i, "A") = MyDir
MyDir = Dir
Wend
End Sub

That represent filename only, unless you want to retrieve all the data of
files you have to use FileSystemObject Scripting metode
 
U

urkec

You can use Dir:

Sub getFiles(startDir As String)

file = Dir(startDir & "\*.*")
i = 1

Do While file <> ""
Sheets(1).Cells(i, 2) = file
i = i + 1
file = Dir
Loop

End Sub


You can also use the FileSystem object:

Sub getFiles1(startDir As String)

Set fso = CreateObject _
("Scripting.FileSystemObject")
Set folder = fso.GetFolder(startDir)

i = 1

For Each file In folder.Files
Sheets(1).Cells(i, 1) = file.Path
i = i + 1
Next
 
C

Costis

Dear Halim,
thank you very mach for your help.
i guess i have to use VBA Excell which i dont know ...
.... going o study
thanks again
 
C

Costis

Dear Urkec,
thank you for your help,
i shall have to learn the basics of VBA
be well
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top