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.)

Comments (10)
  1. JamesNT says:

    I can see creating a script for certain relatives now.


  2. Boris says:

    Since I fail to see cases where permissions to delete such folders would be useful, wouldn't this be better handled by group policy?

  3. kinokijuf says:

    How do i stop Sky^H^H^HOneDrive from recreating the“ObrazyZ aparatu” (“PicturesFrom the apparatus” in Polish, not sure why these folders get created in Polish) folder, when i don’t need it?

  4. alegr1 says:

    Can it be created from JScript?

  5. Nawak says:

    @kinokijuf: I did not test specially your case, but whenever I want to prevent the creation of a folder, I create a file with the same name. (And vice-versa for the automatic creation of files)

  6. Azarien says:

    @kinokijuf: I think your Windows Phone device may be responsible for this.

  7. xp.client says:

    For Libraries, there is a built-in command "Restore default Libraries" when you right click the parent Libraries folder. The Shell team could add a similar "Restore default profile folders" command.

  8. @xp.client says:

    That feature would end up with -99.981 points. Not enough.

  9. kinokijuf says:

    @Azarien especially since i do not have one?

  10. Dave Bacher says:


    Go to and delete the folder there.

    If it comes back, an app is making it — could be a variety of apps, including OneDrive desktop or the Windows 8 app.  The Windows 8 app and various mobile devices like to make a "Camera Roll" folder if they're sent to sync photos, and it might be this is the localized equivalent.  Some devices make a separate "HD."

    That sounds like a mobile device that is set to sync its camera roll to me.

Comments are closed.

Skip to main content