April 23rd, 2014

How do I programmatically create folders like My Pictures if they were manually deleted?

A corporate customer had a problem with their employees accidentally deleting folders like Videos and Pictures and are looking for a way to restore them, short of blowing away the entire user profile and starting over. They found some techniques on the Internet but they don’t always work consistently or completely. What is the recommended way of recreating these missing folders? It turns out that the customer was asking a question that I answered many years ago, but looking at it from the other side. To recreate a folder, call SHGet­Folder­Path with the flag CSIDL_FLAG_CREATE, or call SHGet­Special­Folder­Path and pass fCreate = TRUE. If you are targeting Windows Vista or higher, the known-folder equivalent is calling SHGet­Known­Folder­Path, SHGet­Known­Folder­ID­List, or SHGet­Known­Folder­Item with the KF_FLAG_CREATE flag.

(There is a CSIDL-to-KF conversion table in MSDN.)

Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments

Discussion are closed.