.filetype (1 Viewer)

wazz

Super Moderator
Local time
Today, 16:09
Joined
Jun 29, 2004
Messages
1,711
i'm having trouble writing/interpreting the filetype property of this code. the code searches all files in a folder and returns many different file types but prints "1" as the .FileType for every file. how do i get it to print "Microsoft Word Document" or "BMP File" or "Outlook Item" as appropriate?
Code:
Public Function SearchFolder()

    Dim fs As FileSearch
    Dim i As Integer
    Set fs = Application.FileSearch
    
    With fs
        .LookIn = "C:\Documents and Settings\wazz\etc."
        .SearchSubFolders = True
        .FileType = msoFileTypeAllFiles
        '.FileName = "*.*"
        If .Execute() > 0 Then
            MsgBox "There were " & .FoundFiles.Count & _
             " file(s) found."
            For i = 1 To .FoundFiles.Count
                Debug.Print Mid(.FoundFiles(i), InStrRev(.FoundFiles(i), "\") + 1) & "   " & FileLen(.FoundFiles(i)) & "   " & .FileType
            Next i
        Else
            MsgBox "There were no files found."
        End If
    End With

End Function
 

RoyVidar

Registered User.
Local time
Today, 10:09
Joined
Sep 25, 2000
Messages
805
Two comments on the FileSearch approach

1 - I think the .FileType returns or set the type of file to look for during the search, for the .FileSearch object, I don't think it applies per each file.
2 - the .FileSearch object is removed in the 2007 version, you may want to look into other methods

fso (air code)?

dim fs as object
dim f as object
dim fl as object

set fs=createobject("scripting.filesystemobject")
set fl = fs.getfolder("c:\myfolder\")
for each f in fl.files
debug.print f.name, f.path, f.type
next f
 

wazz

Super Moderator
Local time
Today, 16:09
Joined
Jun 29, 2004
Messages
1,711
thanks a lot for the help. good to know #2! i did happen to discover the filesystemobject just last night and started working with that along with GetFile and several other GetFile... methods that make life easier.

still not sure if it's possible to get "Microsoft Word Document" or "BMP File" or "Outlook Item" along with the extension... tnx
 

RoyVidar

Registered User.
Local time
Today, 10:09
Joined
Sep 25, 2000
Messages
805
.Type is supposed to give you that (last property in the code).
 

wazz

Super Moderator
Local time
Today, 16:09
Joined
Jun 29, 2004
Messages
1,711
yep that's the one. i still had .filetype in my head and missed that.
 

Users who are viewing this thread

Top Bottom