View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
LFCFan LFCFan is offline
external usenet poster
 
Posts: 1
Default Determine file type


Hi David,

Not sure if this is any help to you, but I wrote a little macro a whil
ago that determines file types in a given directory by their extension
It uses activeX so you may need to create some references in you
project:

Sub chFType()
Set fObj = CreateObject("scripting.filesystemobject")
Set dObj = CreateObject("wscript.shell")
dObj.Run "c:\winnt\system32\cmd.exe /c dir c:\ c:\testfTypes.txt", 0
True


Set rFile = fObj.opentextfile("C:\testfTypes.txt", 1, False)

Do Until rFile.atendofstream
currLine = rFile.readLine
getDot = InStr(1, currLine, ".")
If getDot 0 Then
dotExists = Mid(currLine, getDot, 4)
End If

If dotExists = ".xls" Then
MsgBox "I found an excel file! Its called " & currLine
ElseIf dotExists = ".txt" Then
MsgBox "I found a text file! Its called "
currLine
ElseIf dotExists = ".doc" Then
MsgBox "I found a word document! Its calle
" & currLine
Else
MsgBox "This file is not word
Excel or Text!"

End If


Loop

End Sub


Just thinking you could fiddle this code to do different thing
depending on the file type. As you can see there's a few 'ifs' in ther
to tell you what file types are in the directory.

Hope that helps
Jo

--
LFCFa
-----------------------------------------------------------------------
LFCFan's Profile: http://www.excelforum.com/member.php...fo&userid=3748
View this thread: http://www.excelforum.com/showthread.php?threadid=57136