Suedocode
Suedocode

Reputation: 2534

Custom folder icons with desktop.ini & instant refreshing

I am tasked with creating a book-keeping program that tracks some statistics of when files and folders are read. Similar to Google Drive and TortoiseSVN, the folder and file icons should reflect certain changes. For instance, a USB with files that haven't been viewed on a certain computer have an 'x', whereas viewed files get a 'o'.

I can track file usage with this Windows API, and icons (as well as some other nice options) can be changed by the desktop.ini files [1,2,3,4].

While manually messing around with desktop.ini files, I've successfully changed icons, descriptions, and other fun stuff. The problem is that the new changes don't update until Windows parses the desktop.ini file again. This tends to happen inconsistently between a few seconds to several minutes. F5 refreshes do not force a reparse, but will update the image if a reparse has occurred.

How do I force Windows to reparse desktop.ini files both manually and (more importantly) in a C++ program?

Is there an alternative C++ Windows API that can change folder icons immidiately?

Upvotes: 3

Views: 2689

Answers (3)

olderciyuan
olderciyuan

Reputation: 1

string folder = "folder";
// Edit your folder\\desktop.ini
string flush = "attrib +s "+folder;
system(flush.c_str());

You can use this C++ code to flush your desktop.ini in 'folder'

Upvotes: 0

Ranjan
Ranjan

Reputation: 1

If you wish to have different folder icons to indicate different states distinctively (similar to SVN) then you need icon overlays. Changing folder icons is not the suitable solution. The changes in folder icons will reflect instantaneously If you need further details, Please let me know.

Upvotes: 0

Peter Tseng
Peter Tseng

Reputation: 14003

If you edit desktop.ini, it Explorer won't refresh automatically. Use SHGetSetFolderCustomSettings to write to it:

SHFOLDERCUSTOMSETTINGS fcs = {0};
fcs.dwSize = sizeof(SHFOLDERCUSTOMSETTINGS);
fcs.dwMask = FCSM_ICONFILE;
fcs.pszIconFile = iconPath;
fcs.cchIconFile = 0;
fcs.iIconIndex = iconIndex;
SHGetSetFolderCustomSettings(&fcs, folderPath, FCS_FORCEWRITE);

Upvotes: 2

Related Questions