Where are the states of opened/closed folders saved in OS X?
I presume you are referring to listing a folder using the disclosure triangle in list view:



The state of shown/hidden folders in list view of a specific folder is stored in Finder cache, as well as the folder's hidden .DS_Store.

.
├── .DS_Store
├── 1
│   └── hello.txt
...


You can reset a folder's folder disclosure triangle by running the following command inside the folder that you wish to reset:

rm .DS_Store &amp;&amp; killall -HUP Finder