Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Reading files on a specific folders

How would I read the content of a folder and output all
files names (such as file names, file type, date & time,
etc) into a spreadsheet.

Any Idea?

Thanks in advance!
Jaime
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Reading files on a specific folders

Try this

Run this with a empty sheet active

Sub test2()
Dim i As Long
With Application.FileSearch
.NewSearch
.LookIn = "c:\Data"
.SearchSubFolders = False
.MatchTextExactly = False
.FileType = msoFileTypeAllFiles
If .Execute(msoSortOrderDescending) 0 Then
MsgBox "There were " & .FoundFiles.Count & " file(s) found."
For i = 1 To .FoundFiles.Count
Cells(i, 1).Value = .FoundFiles(i)
Cells(i, 2).Value = FileDateTime(.FoundFiles(i))
Cells(i, 3).Value = FileLen(.FoundFiles(i))
Next i
Else
MsgBox "There were no files found."
End If
End With
End Sub




--
Regards Ron de Bruin
http://www.rondebruin.nl


"Jaime" wrote in message ...
How would I read the content of a folder and output all
files names (such as file names, file type, date & time,
etc) into a spreadsheet.

Any Idea?

Thanks in advance!
Jaime



  #3   Report Post  
Posted to microsoft.public.excel.programming
rog rog is offline
external usenet poster
 
Posts: 39
Default Reading files on a specific folders

Jaime, the following code requires you to set a reference
to Microsoft Scripting Runtime - do this by going to the
menu items Tools|references

change your starting PATH to the root folder, and run the
getfiles macro



Public Sub GetFiles()

Const PATH As String = "C:\Mcskew"
Dim objFSo As New FileSystemObject
Dim objFolder As Folder
Dim rngOut As Range

Set rngOut = Range("A1")
Set objFolder = objFSo.GetFolder(PATH)

Process rngOut, objFolder

End Sub

Public Sub Process(ByRef p_rngOut As Range, ByRef
p_objFolder As Folder)

Dim objFolder As Folder
Dim objFile As File

For Each objFile In p_objFolder.Files
p_rngOut.Value = objFile.Name
p_rngOut.Offset(0, 1).Value = objFile.PATH
p_rngOut.Offset(0, 2).Value = objFile.Type
Set p_rngOut = p_rngOut.Offset(1)
Next

For Each objFolder In p_objFolder.SubFolders
Process p_rngOut, objFolder
Next

End Sub



Rgds

Rog

PS isn't recursion great!

-----Original Message-----
How would I read the content of a folder and output all
files names (such as file names, file type, date & time,
etc) into a spreadsheet.

Any Idea?

Thanks in advance!
Jaime
.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
.TMP files are corrupting my folders Ed Excel Discussion (Misc queries) 2 February 8th 08 02:08 PM
undelete files or folders? Tasing Excel Discussion (Misc queries) 0 January 1st 06 10:55 PM
links to same files in different folders Henk Excel Worksheet Functions 2 August 19th 05 02:48 AM
Opening Files/Folders animalfriend7 Excel Discussion (Misc queries) 2 June 23rd 05 11:57 PM
Drive - Folders - Files DPC Excel Discussion (Misc queries) 1 May 26th 05 08:39 PM


All times are GMT +1. The time now is 01:23 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"