How to detect if folder exist (and ignore file with same name ;))
Today I experienced really annoying bug with one of my scripts. It is checking if one folder (in quite complex structure) exists(If Exist Folder...), if it does, it perfoms some actions and send few mails. However after some time it started to behave strange - it was sending sometimes mail when folder was definitely not there etc.
It didnt take me long time to discover what was the problem - another team was using file without extension with same name as my folder :) So I rewrote today this script to detect ONLY folder and ignore files with same name.
How to do it? Its quite simle
If Exist Folder\nul.ext Send-Mail
For example If Exit C:\Temp\test\nul.ext will be True if folder test exists, however not if file test exists.
You just need to be very careful - Windows doesnt allow you to have folder and file with same name in same folder:
C:\Temp>mkdir Test
C:\Temp>Echo.>test
Access is denied.
C:\Temp>rmdir Test
C:\Temp>Echo.>test
C:\Temp>mkdir Test
A subdirectory or file Test already exists.
C:\Temp>