in reply to Quickest way to get a list of all folders in a directory

First, you're not building the string you intend to since "\" and "$" are special in double quoted string literals. You need to escape them with a "\". Didn't you get a file not found error? You should have verified what string you were passing to open.

Second, you need opendir instead of open.