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

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.

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,112,885
Messages
5,543,028
Members
410,583
Latest member
gazz57
Top