Home |
Search |
Today's Posts |
|
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Find latest file in folder & Open | Excel Programming | |||
VBA can't find file as it moves from folder to folder | Excel Programming | |||
Save file in a new folder, but create folder only if folder doesn't already exist? | Excel Programming | |||
Find New File/Folder | Excel Programming | |||
Find Folder Path + file Name Length and Insert into Spreadsheet | Excel Programming |