Samm1502
asked on
How to make the Dir() function case insensitive
Hi there
My application needs to get all files with the extension .DAT in a particular directory and at the moment the
call to DIr looks like this:
gstrDATFiles = gstrDirPath & "*.DAT"
'Now process all files
strFileName = Dir(gstrDATFiles, vbNormal)
and it does the job bt requires that all filenames be in upper case. What I want is to get all
files ending .Dat or .DAT or .dat or even .dAt so that I am not restricted by case.
Anyone any ideas.
Many thanks
Sam
My application needs to get all files with the extension .DAT in a particular directory and at the moment the
call to DIr looks like this:
gstrDATFiles = gstrDirPath & "*.DAT"
'Now process all files
strFileName = Dir(gstrDATFiles, vbNormal)
and it does the job bt requires that all filenames be in upper case. What I want is to get all
files ending .Dat or .DAT or .dat or even .dAt so that I am not restricted by case.
Anyone any ideas.
Many thanks
Sam
The Dir$() or Dir() function is not case sensitive, so you should have no problem. Can you suggest that you check again?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You are probably already stepping through a loop, but just in case you are not, this is what it should look like.
Sub WalkThroughFolder()
Dim strFileName As String
gstrDATFiles = gstrDirPath & "*.DAT"
strFileName = Dir$(gstrDATFiles, vbNormal)
Do Until strFileName = ""
'process file gstrDirPath & strFileName
strFileName = Dir$()
Loop
End Sub
Sub WalkThroughFolder()
Dim strFileName As String
gstrDATFiles = gstrDirPath & "*.DAT"
strFileName = Dir$(gstrDATFiles, vbNormal)
Do Until strFileName = ""
'process file gstrDirPath & strFileName
strFileName = Dir$()
Loop
End Sub
dir is case insensitive
Private Sub Form_Load()
Dim sTemp As String
sTemp = Dir(sTemp, vbNormal)
While sTemp <> ""
Debug.Print sTemp
sTemp = Dir()
Wend
End Sub
Private Sub Form_Load()
Dim sTemp As String
sTemp = Dir(sTemp, vbNormal)
While sTemp <> ""
Debug.Print sTemp
sTemp = Dir()
Wend
End Sub
ASKER
Many thanks - sorry for delay
This was handed to me as a problem but in fact it does process fileswith names of all cases.
Thanks!
This was handed to me as a problem but in fact it does process fileswith names of all cases.
Thanks!
You're welcome.
set fso = createobject("scripting.fi
dim folder as object
set folder = fso.getfolder(gstrDatfiles
dim file as object
for each file in folder.files
if ucase(file.name) like "*.DAT" then
...
end if
next