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
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
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?
 
Upvote 0

Forum statistics

Threads
1,214,601
Messages
6,120,467
Members
448,965
Latest member
grijken

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top