Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default find out if its a folder or file

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
XP XP is offline
external usenet poster
 
Posts: 389
Default find out if its a folder or file

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...

"Rivers" wrote:

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,069
Default find out if its a folder or file

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

"Rivers" wrote:

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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Find latest file in folder & Open Les Excel Programming 2 March 26th 08 07:01 AM
VBA can't find file as it moves from folder to folder pdberger Excel Programming 1 March 8th 07 01:08 AM
Save file in a new folder, but create folder only if folder doesn't already exist? nbaj2k[_40_] Excel Programming 6 August 11th 06 08:41 PM
Find New File/Folder BOONER Excel Programming 2 July 20th 06 04:25 PM
Find Folder Path + file Name Length and Insert into Spreadsheet Steve Roberts Excel Programming 1 July 26th 05 06:01 PM


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"