-1

To programatically change the icon of a folder, I found that I need to set the folder's attribute to be a system folder.

Guide I worked with: http://www.codeproject.com/Articles/9331/Create-Icons-for-Folders-in-Windows-Explorer-Using

And the relevant code:

File.SetAttributes(folderPath, File.GetAttributes(folderPath) | FileAttributes.System);

Looking at the documentation, this function should have thrown an exception for a folder path as parameter:

https://msdn.microsoft.com/en-us/library/system.io.file.setattributes%28v=vs.110%29.aspx

Is this really the correct API?

In addition, what are the consequences of setting it as a system folder?

Mugen
  • 8,301
  • 10
  • 62
  • 140
  • I feel that setting system attribute to a folder is weird way to accomplish this. It does work, but when I change the folder icon from Explorer the attribute is not set, so there should be another, proper way to do it. – Dialecticus Jun 01 '15 at 12:48

1 Answers1

2

SetFileAttributes function works both on files and directories, and File.SetAttributes calls it underneath. So it's the correct API. I see no mentioning of raising exceptions on folders. There is one if the path to the folder is on network drive, but that just means that the function accepts folders, just not bad folders.

As for setting the folder attribute to system, it's arguably less annoying if it's set to read-only. The effect is the same.

Dialecticus
  • 16,400
  • 7
  • 43
  • 103