find out if its a folder or file

R

Rivers

hi guys i need help a little help

myfile contains a folder path or a file i need a way to determine which one
it is i tried the instr below but found that files with a "." in missed my
loop totally so this doesnot suit my needs is this possible to do?

myFile = Dir(myPath, vbDirectory)
Do While myFile <> "" 'will start LOOP until all files in folder
If InStr(myFile, ".") > 0 Then
 
X

XP

You may be able to test for the presence of a file extension?

Sub Test()
myPath = "c:\test.txt"
If FileExtension(myPath) = "" Then MsgBox "a folder" Else MsgBox "a file"
End Sub

Public Function FileExtension(argFullorFileName As String) As String
Dim oFSO As Object
Set oFSO = CreateObject("Scripting.FileSystemObject")
FileExtension = oFSO.GetExtensionName(argFullorFileName)
End Function

Hope this helps...
 
T

Tom Hutchins

Maybe something like this:

Sub FilesAndFolders()
Dim myPath As String, myFile As String
myPath = "D:\Data\"
myFile = Dir(myPath, vbDirectory)
Do While myFile <> ""
If myFile <> "." And myFile <> ".." Then
If (GetAttr(myPath & myFile) And vbDirectory) <> 0 Then
MsgBox "Folder: " & myPath & myFile
Else
MsgBox "File: " & myPath & myFile
End If
End If
myFile = Dir()
Loop
End Sub

Hope this helps,

Hutch
 

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

Top