Enumerating files in VBA

S

Steve Rindsberg

It's easy enough to get a listing of specific file types in a given folder in
VBA using something like this (sFolder and sFileType assumed to be string
variables set to the name of the folder and file Type you're after):

sFileName = Dir$(sFolder, MacID(sFileType))
While sFileName <> ""
Debug.Print sFileName
sFileName = Dir$()
Wend

But what if you want a listing of ALL files in a given folder? What do you use
for sFileType? Null doesn't appear to work.

What if you want a listing of files that have no type (files from a PC, for
example)? Files that return a type of "" when queried by
/developer/tools/getfileinfo "filename"

And while we're at it, is it also possible to get a listing of folders within a
folder? If not, is it possible to traverse a directory tree to get listings of
files within folders within folders and so on?

TIA ...

--
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================
Featured Presenter, PowerPoint Live 2004
October 10-13, San Diego, CA www.PowerPointLive.com
================================================
 
J

Jim Gordon MVP

Hi Steve,

This snippet may be enough to help you.

Sub trythis()
Dim CurrentPath
Dim FullPath
Let CurrentPath = CurDir
MsgBox CurDir
Dir (CurrentPath)
Dir ("")
Let FullPath = CurDir
Debug.Print FullPath
End Sub

The key part is dir("")

-Jim


It's easy enough to get a listing of specific file types in a given folder in
VBA using something like this (sFolder and sFileType assumed to be string
variables set to the name of the folder and file Type you're after):

sFileName = Dir$(sFolder, MacID(sFileType))
While sFileName <> ""
Debug.Print sFileName
sFileName = Dir$()
Wend

But what if you want a listing of ALL files in a given folder? What do you
use
for sFileType? Null doesn't appear to work.

What if you want a listing of files that have no type (files from a PC, for
example)? Files that return a type of "" when queried by
/developer/tools/getfileinfo "filename"

And while we're at it, is it also possible to get a listing of folders within
a
folder? If not, is it possible to traverse a directory tree to get listings
of
files within folders within folders and so on?

TIA ...

--
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================
Featured Presenter, PowerPoint Live 2004
October 10-13, San Diego, CA www.PowerPointLive.com
================================================

--
Jim Gordon
Mac MVP

MVPs are not Microsoft Employees
MVP info
 
S

Steve Rindsberg

Hi Jim,

Yup, found that trick a while back and it does work nicely; still looking for a
way of enumerating folders as well.



Jim Gordon MVP said:
Hi Steve,

This snippet may be enough to help you.

Sub trythis()
Dim CurrentPath
Dim FullPath
Let CurrentPath = CurDir
MsgBox CurDir
Dir (CurrentPath)
Dir ("")
Let FullPath = CurDir
Debug.Print FullPath
End Sub

The key part is dir("")

-Jim

--
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================
Featured Presenter, PowerPoint Live 2004
October 10-13, San Diego, CA www.PowerPointLive.com
================================================
 

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

Similar Threads

Code to search subfolders 1
oPresentation.SaveAs ... PowerPoint2007 2
ListView IconFiles show 0
List files on SharePoint 0
VBA - Image Control question 2
Automate embedding files 1
Mac PPT VBA IDE 4
MacID VBA 2

Top