How to check if a directory is existed?

VitaminB6

Board Regular
Joined
Oct 11, 2004
Messages
208
Follow code is part of my code to check every file's date in a directory, PathForTime, However, I found some of the subfolder may not contain "\ISIS\, and then I use IF Dir(myFileName2) <> "" to check if the subfolder exists. One error message shows up until "myFileName = Dir()". I wondered what was happened? My intention is to check if the subfolder, "ISIS", is in the directory or not? Can someone help me with this?

myFileName = Dir(PathForTime, 16)
Do While Len(myFileName) > 0
If Left(myFileName, 2) = "PE" Or Left(myFileName, 2) = "JE" Then
LotDateForSK = DateValue(FileDateTime(PathForTime & myFileName))

If LotDateForSK >= FromDateForTime And LotDateForSK <= ToDateForTime Then
myFileName2 = PathForTime & myFileName & "\ISIS\"
If Dir(myFileName2) <> "" Then
LotIDArray(LotIDTemp) = myFileName2
LotIDTemp = LotIDTemp + 1
End If
End If
End If
myFileName = Dir()
Loop
 

Some videos you may like

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

VitaminB6

Board Regular
Joined
Oct 11, 2004
Messages
208
I observed onething which is if ISIS folder does exist, no error message shows up, however, we get an error message as the ISIS subfolder is not in the directory.
Can Anyone help?
 

Watch MrExcel Video

Forum statistics

Threads
1,119,118
Messages
5,576,202
Members
412,706
Latest member
msousa25
Top