Directory Printer

M

MD

Does anyone have a ready-made FORM (or code only) for printing the content
(FileName, Date, Time, size) of a directory. I found this neat application
(freeware) on http://www.spadixbd.com/freetools/ but I am looking for
something to incorporate an EXCEL program.

Reagrds

Michel
 
S

Steve Yandl

I did the project with code below for someone just interested in the file
names and date information but it should be very simple to add file size or
other parameters you might want...Steve

First Create a reference to "Microsoft Scripting Runtime" (Tools >
References) in VBE.

In module 1:

Sub DoNewFolder()
Workbooks.Add
Dim fd As FileDialog
Dim strPath As String
Dim B As Integer
Dim IncludeSubfolders As Boolean
Set fd = Application.FileDialog(msoFileDialogFolderPicker)
Dim selFldr As Variant
With fd
If .Show = -1 Then
For Each selFldr In .SelectedItems
strPath = selFldr & "\"
Next selFldr
Else
End If
End With
IncludeSubfolders = False
B = MsgBox("Include Subfolders?", vbYesNo, "Scope")
If B = 6 Then
IncludeSubfolders = True
Else
IncludeSubfolders = False
End If

With Range("A1")
.Formula = "Folder Contents: " & strPath
.Font.Bold = True
.Font.Size = 12
End With
Range("A3").Formula = " "
Range("B3").Formula = "File Name"
Range("C3").Formula = "Date Created"
Range("D3").Formula = "Date Last Modified"
Range("E3").Formula = "Date Last Accessed"
Range("A3:E3").Font.Bold = True
ListFilesInFolder strPath, IncludeSubfolders
Range("A2").Select
End Sub


Sub ListFilesInFolder(SourceFolderName As String, AlsoSubfolders As Boolean)
Dim FSO As Scripting.FileSystemObject
Dim SourceFolder As Scripting.Folder, SubFolder As Scripting.Folder
Dim FileItem As Scripting.File
Dim r As Long
Set FSO = New Scripting.FileSystemObject
Set SourceFolder = FSO.GetFolder(SourceFolderName)
r = Range("A65536").End(xlUp).Row + 1
For Each FileItem In SourceFolder.Files
Cells(r, 1).Formula = " "
Cells(r, 2).Formula = FileItem.Name
Cells(r, 3).Formula = FileItem.DateCreated
Cells(r, 4).Formula = FileItem.DateLastModified
Cells(r, 5).Formula = FileItem.DateLastAccessed
r = r + 1
Next FileItem
If AlsoSubfolders Then
For Each SubFolder In SourceFolder.SubFolders
r = Range("A65536").End(xlUp).Row + 1
Cells(r, 1).Formula = SubFolder.Path
ListFilesInFolder SubFolder.Path, True
Next SubFolder
End If
Columns("B:E").AutoFit
Set FileItem = Nothing
Set SourceFolder = Nothing
Set FSO = Nothing
End Sub


Under "ThisWorkbook":

Private Sub Workbook_Open()
Workbooks.Add
Dim fd As FileDialog
Dim strPath As String
Dim B As Integer
Dim IncludeSubfolders As Boolean
Set fd = Application.FileDialog(msoFileDialogFolderPicker)
Dim selFldr As Variant
With fd
If .Show = -1 Then
For Each selFldr In .SelectedItems
strPath = selFldr & "\"
Next selFldr
Else
End If
End With
IncludeSubfolders = False
B = MsgBox("Include Subfolders?", vbYesNo, "Scope")
If B = 6 Then
IncludeSubfolders = True
Else
IncludeSubfolders = False
End If

With Range("A1")
.Formula = "Folder Contents: " & strPath
.Font.Bold = True
.Font.Size = 12
End With
Range("A3").Formula = " "
Range("B3").Formula = "File Name"
Range("C3").Formula = "Date Created"
Range("D3").Formula = "Date Last Modified"
Range("E3").Formula = "Date Last Accessed"
Range("A3:E3").Font.Bold = True
ListFilesInFolder strPath, IncludeSubfolders
Range("A2").Select
End Sub
 
G

George

Hi,

I've yet to try the code, but am looking for something, which I'm not
sure if this thread addressed.

I would like to have an Excel ss file list for me, in separate
columns, all my files, in certain directories, giving all information
like file size, date, etc.

1 column = 1 certain directory.
4 or 5 rows in that column to spec the listed file (file size, date,
etc).

Thanks,
George
 
G

Gord Dibben

George

Several methods to accomplish this.......I like Tushar's best.

To add a "Print Directory" feature to Explorer, go to
this KB Article.

http://support.microsoft.com/default.aspx?scid=KB;EN-US;q272623&

Or you can download Printfolder 1.2 from.....

http://no-nonsense-software.com/freeware/

I use PF 1.2 and find it to be more than adequate with custom features.

OR Go to DOS(Command) prompt and directory.
Type DIR >MYFILES.TXT

All the above create a *.TXT file which can be opened in Excel.

One more method if you want to by-pass the *.TXT file and pull directly to
Excel is to use Tushar Mehta's Excel Add-in. This allows filtering and
sorting once you have the data in Excel.

http://www.tushar-mehta.com/ scroll down to Add-ins>Directory Listing.

Download the ZIP file and un-zip to your Office\Library folder.

Gord Dibben Excel MVP
 
J

Jim Cone

George,

Or you may want to give my "List Files" add-in a try.
You get the option to determine the type of files you want to list.
In addition, the file names are hyperlinked.
(includes button to remove all hyperlinks)
Free upon direct request - remove xxx from my email address.

Regards,
Jim Cone
San Francisco, CA
[email protected]

George said:
Hi,
I've yet to try the code, but am looking for something, which I'm not
sure if this thread addressed.
I would like to have an Excel ss file list for me, in separate
columns, all my files, in certain directories, giving all information
like file size, date, etc.
1 column = 1 certain directory.
4 or 5 rows in that column to spec the listed file (file size, date,> etc).
Thanks,
George

- snip -
 
Top