PC Review


Reply
Thread Tools Rate Thread

Display Contents of Folder

 
 
=?Utf-8?B?Q2hhZA==?=
Guest
Posts: n/a
 
      16th Oct 2007
I'm in need of VBA code that will list in an Excel sheet the filenames of all
documents of a specific folder. Any help on this is much appreciated.

Thanks,
Chad
 
Reply With Quote
 
 
 
 
Crowbar via OfficeKB.com
Guest
Posts: n/a
 
      16th Oct 2007
This will do that, it stores them in an array then writes it to sheet1

Function GetFileNames()

Dim MyName, MyPath
Dim FNames()

'Find how many file exist

ReDim FNames(0)

MyPath = "C:\" 'You need to change this to your requirement
MyName = Dir(MyPath, vbDirectory)
Do While MyName <> ""

If MyName <> "." And MyName <> ".." Then

On Error Resume Next
If (GetAttr(MyPath & MyName) And vbDirectory) <> vbDirectory Then
ReDim Preserve FNames(UBound(FNames) + 1)
FNames(UBound(FNames)) = MyPath & MyName
End If

End If

MyName = Dir

Loop

For x = 1 To UBound(FNames)
Sheet1.Cells(x, 1) = FNames(x)
Next x

End Function

--
Message posted via http://www.officekb.com

 
Reply With Quote
 
Zone
Guest
Posts: n/a
 
      16th Oct 2007
This will put a list of files in column G. Change MYPATH to the path for
the folder you want to look at, ending with a backslash \ Hope this
helps, James

Const MYPATH = "c:\MyFiles\"

Sub ListFiles()
Dim PutRow As Long, fName As String
PutRow = 1
Columns("g").Clear
fName = Dir(MYPATH & "*.*")
Cells(PutRow, "g") = fName
PutRow = PutRow + 1
Do
fName = Dir
Cells(PutRow, "g") = fName
PutRow = PutRow + 1
Loop Until fName = ""
End Sub

"Chad" <(E-Mail Removed)> wrote in message
news:6E629E4A-7C30-48FF-8D50-(E-Mail Removed)...
> I'm in need of VBA code that will list in an Excel sheet the filenames of
> all
> documents of a specific folder. Any help on this is much appreciated.
>
> Thanks,
> Chad



 
Reply With Quote
 
=?Utf-8?B?UGF1bCBDb3JkdHM=?=
Guest
Posts: n/a
 
      16th Oct 2007
I use this routine

Sub Searchfolder()

Set fs = Application.FileSearch
With fs
.LookIn = "C:\Documents and Settings\User\My Documents" 'Your path here
.Filename = "*"
.Searchsubfolders = False
If .Execute(SortBy:=msoSortByFileName, _
SortOrder:=msoSortOrderAscending) > 0 Then
MsgBox "There were " & .FoundFiles.Count & _
" file(s) found."

For I = 1 To .FoundFiles.Count
'Truncate to File Name
flstring = .FoundFiles(I)
namelen = InStrRev(flstring, "\")
flstring = Right(flstring, Len(flstring) - namelen)
'Output to sheet
ActiveCell = flstring
ActiveCell.Offset(1, 0).Select
Next I
Else
MsgBox "There were no files found."
End If
End With

End Sub

"Chad" wrote:

> I'm in need of VBA code that will list in an Excel sheet the filenames of all
> documents of a specific folder. Any help on this is much appreciated.
>
> Thanks,
> Chad

 
Reply With Quote
 
=?Utf-8?B?Q2hhZA==?=
Guest
Posts: n/a
 
      16th Oct 2007
I think this will work perfectly. Thank you so much!

-Chad


"Crowbar via OfficeKB.com" wrote:

> This will do that, it stores them in an array then writes it to sheet1
>
> Function GetFileNames()
>
> Dim MyName, MyPath
> Dim FNames()
>
> 'Find how many file exist
>
> ReDim FNames(0)
>
> MyPath = "C:\" 'You need to change this to your requirement
> MyName = Dir(MyPath, vbDirectory)
> Do While MyName <> ""
>
> If MyName <> "." And MyName <> ".." Then
>
> On Error Resume Next
> If (GetAttr(MyPath & MyName) And vbDirectory) <> vbDirectory Then
> ReDim Preserve FNames(UBound(FNames) + 1)
> FNames(UBound(FNames)) = MyPath & MyName
> End If
>
> End If
>
> MyName = Dir
>
> Loop
>
> For x = 1 To UBound(FNames)
> Sheet1.Cells(x, 1) = FNames(x)
> Next x
>
> End Function
>
> --
> Message posted via http://www.officekb.com
>
>

 
Reply With Quote
 
Chip Pearson
Guest
Posts: n/a
 
      16th Oct 2007
You can use my DirTree add-in that will list the subfolders and files of a
specified folder, with many display options. See
www.cpearson.com/Excel/FolderTree.aspx


--
Cordially,
Chip Pearson
Microsoft MVP - Excel, 10 Years
Pearson Software Consulting
www.cpearson.com
(email on the web site)

"Chad" <(E-Mail Removed)> wrote in message
news:6E629E4A-7C30-48FF-8D50-(E-Mail Removed)...
> I'm in need of VBA code that will list in an Excel sheet the filenames of
> all
> documents of a specific folder. Any help on this is much appreciated.
>
> Thanks,
> Chad


 
Reply With Quote
 
cubbybear3
Guest
Posts: n/a
 
      16th Oct 2007
Is it possible to access the indvidual file attributes that I can view
in different columns within Windows 'Exploder' (ie: Attributes, Owner,
Author, Title, Artist, etc)? And if so, are there any VBA examples
out there I could look at? Thanks. -pb

 
Reply With Quote
 
Gord Dibben
Guest
Posts: n/a
 
      16th Oct 2007
I suggest downloading Tushar's Directory Listing add-in from

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 MS Excel MVP

On Tue, 16 Oct 2007 13:59:46 -0700, cubbybear3 <(E-Mail Removed)> wrote:

>Is it possible to access the indvidual file attributes that I can view
>in different columns within Windows 'Exploder' (ie: Attributes, Owner,
>Author, Title, Artist, etc)? And if so, are there any VBA examples
>out there I could look at? Thanks. -pb


 
Reply With Quote
 
=?Utf-8?B?Q2hhZA==?=
Guest
Posts: n/a
 
      17th Oct 2007
Is it possible to get a list of the entire folder contents, including other
folders that may exist? This code works perfectly to list all files outside
of folders within the desired destination.

Thanks!


"Zone" wrote:

> This will put a list of files in column G. Change MYPATH to the path for
> the folder you want to look at, ending with a backslash \ Hope this
> helps, James
>
> Const MYPATH = "c:\MyFiles\"
>
> Sub ListFiles()
> Dim PutRow As Long, fName As String
> PutRow = 1
> Columns("g").Clear
> fName = Dir(MYPATH & "*.*")
> Cells(PutRow, "g") = fName
> PutRow = PutRow + 1
> Do
> fName = Dir
> Cells(PutRow, "g") = fName
> PutRow = PutRow + 1
> Loop Until fName = ""
> End Sub
>
> "Chad" <(E-Mail Removed)> wrote in message
> news:6E629E4A-7C30-48FF-8D50-(E-Mail Removed)...
> > I'm in need of VBA code that will list in an Excel sheet the filenames of
> > all
> > documents of a specific folder. Any help on this is much appreciated.
> >
> > Thanks,
> > Chad

>
>
>

 
Reply With Quote
 
Zone
Guest
Posts: n/a
 
      18th Oct 2007
Change it like this to get files plus subdirectories.

fName = Dir(MYPATH, vbDirectory)

This doesn't show the files within the subdirectories, but you can do add
the subdirectories to the path one at a time, then do Dir to get those
files. HTH, James

"Chad" <(E-Mail Removed)> wrote in message
news:891A8E6B-D7AB-4C4B-BDB0-(E-Mail Removed)...
> Is it possible to get a list of the entire folder contents, including
> other
> folders that may exist? This code works perfectly to list all files
> outside
> of folders within the desired destination.
>
> Thanks!
>
>
> "Zone" wrote:
>
>> This will put a list of files in column G. Change MYPATH to the path for
>> the folder you want to look at, ending with a backslash \ Hope this
>> helps, James
>>
>> Const MYPATH = "c:\MyFiles\"
>>
>> Sub ListFiles()
>> Dim PutRow As Long, fName As String
>> PutRow = 1
>> Columns("g").Clear
>> fName = Dir(MYPATH & "*.*")
>> Cells(PutRow, "g") = fName
>> PutRow = PutRow + 1
>> Do
>> fName = Dir
>> Cells(PutRow, "g") = fName
>> PutRow = PutRow + 1
>> Loop Until fName = ""
>> End Sub
>>
>> "Chad" <(E-Mail Removed)> wrote in message
>> news:6E629E4A-7C30-48FF-8D50-(E-Mail Removed)...
>> > I'm in need of VBA code that will list in an Excel sheet the filenames
>> > of
>> > all
>> > documents of a specific folder. Any help on this is much appreciated.
>> >
>> > Thanks,
>> > Chad

>>
>>
>>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
how do I display the contents of a published folder nhsman Microsoft Frontpage 0 19th Mar 2009 02:40 PM
Display Contents of a Folder =?Utf-8?B?RHdpZ2h0?= Microsoft Access Forms 3 28th Jun 2006 07:06 PM
Display the contents of a folder in a listbox? Paul H Microsoft VB .NET 9 27th Mar 2006 08:40 PM
display folder contents =?Utf-8?B?Qm9i?= Windows XP General 12 24th Nov 2005 07:50 PM
display folder contents =?Utf-8?B?SGVucnkgQXJkaWZm?= Microsoft Frontpage 1 16th May 2004 04:00 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:24 PM.