automate program that change folder icon if empty (red) or not (green)

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: automate program that change folder icon if empty (red) or not (green)

22 May 2017, 08:01

because sometimes it take time to show the new icon,
IMHO you shouldn't delete those INIs. Simply use AHK's INIWrite to change the icons keyValue. Window refresh > F5 ??
To recreate an INI every time you want to change the icon(setting) is probably slowing down the processing of the icon (+ network credential settings etc ...??)
a_God_Rabbit
Posts: 14
Joined: 19 May 2017, 04:46

Re: automate program that change folder icon if empty (red) or not (green)

22 May 2017, 09:13

Oh yes can be a good idea to modify the ini text content !
asieruta

Re: automate program that change folder icon if empty (red) or not (green)

09 Oct 2017, 06:03

Hello
The code is great, thanks! :dance:

I am trying to modify it so that it will not only change the icon if the folder is empty, but also set a predefined icon if specific folders inside the structure are empty or not.

My structure look like this:
> MAIN FOLDER
>> FOLDER for each new job
>>> 01 Korespondencja
>>> 02 Rysunki do zatwierdzenia
>>> 03 Rysunki zatwierdzone
... etc

Right now the script changes the icon of "FOLDER for each new job" when whole folder with contents is empty.
What I need the script to do is to change the icon of "FOLDER for each new job" based on contents of predefined structure.

For example:
- if the content of FOLDER is empty, the icon is changed to "empty icon",
- if the "01 Korespondencja" folder inside specific "FOLDER for each new job" is not empty, the icon (for "FOLDER for each new job") would change to icon "1",
- if the "03 Rysunki zatwierdzone" is not empty, the icon (for "FOLDER for each new job") would change to icon "3".
(If folder 03 is not empty, it doesn't need to check if previous (01, 02) folders are empty or not)

I will of course get the needed .ico files myself.

Thanks for any help!
teadrinker
Posts: 4331
Joined: 29 Mar 2015, 09:41
Contact:

Re: automate program that change folder icon if empty (red) or not (green)

09 Oct 2017, 08:51

a_God_Rabbit wrote:Other good idea, i don't know if will try it now or not, is to refresh folder icon preview every time the script get executed, because sometime it take time to show the new icon
To change a folder icon immediately:

Code: Select all

SetFolderIcon(A_ScriptDir . "\TestFolder", A_WinDir . "\System32\Shell32.dll", 80)

SetFolderIcon(folderPath, iconPath, iconIndex)  {
   static FCSM_ICONFILE := 0x10, FCS_FORCEWRITE := 0x2
   if !A_IsUnicode  {
      VarSetCapacity(WiconPath, StrPut(iconPath, "UTF-16")*2, 0)
      StrPut(iconPath, &WiconPath, "UTF-16")
   }
   VarSetCapacity(SHFOLDERCUSTOMSETTINGS, size := 4*5 + A_PtrSize*10, 0)
   NumPut(size, SHFOLDERCUSTOMSETTINGS)
   NumPut(FCSM_ICONFILE, SHFOLDERCUSTOMSETTINGS, 4)
   NumPut(A_IsUnicode ? &iconPath : &WiconPath, SHFOLDERCUSTOMSETTINGS, 4*2 + A_PtrSize*8)
   NumPut(iconIndex, SHFOLDERCUSTOMSETTINGS, 4*2 + A_PtrSize*9 + 4)
   DllCall("Shell32\SHGetSetFolderCustomSettings", Ptr, &SHFOLDERCUSTOMSETTINGS, WStr, folderPath, UInt, FCS_FORCEWRITE)
}
desktop.ini will be updated or created automatically.
farhanriktigregnskap
Posts: 1
Joined: 13 Mar 2020, 03:02

Re: automate program that change folder icon if empty (red) or not (green)

13 Mar 2020, 04:13

Hi,
Does this script work on windows 10 ?
a_God_Rabbit wrote:
22 May 2017, 04:17
Yes ! Thk you i'm very happy, your last test work fine, i'll use it.

I'll work like this now because i don't have much time to spend on it but i'll try to get it better later because as you said it can be great in fact if we can not use desktop.ini. I'll check when i have time to do this, now i know it's possible. Actually desktop.ini is hidden and invisible so it'll not disturb our employee so we can deal with it temporary at least.

Here the code working well

Code: Select all

#NoEnv
#SingleInstance Force
SendMode Input
SetWorkingDir %A_ScriptDir%


!f::
	myRootFolder := "C:\Users\bloody36\Desktop\MeoW"

	Loop, %myRootFolder%\*.*,2,1
    		{
		status := (countFiles(A_LoopFileFullPath)=0) ? "empty" : "not empty"

		ToolTip % A_LoopFileLongPath " is " status

		If (status = "empty")
	
			FileAppend, 
			(
			[.ShellClassInfo]
			InfoTip= Empty Folder !!!
			ConfirmFileOp=0
			IconFile=C:\Icons8-Windows-8-Numbers-1-Black.ico
			IconIndex=0
			)`n, %A_LoopFileLongPath%\Desktop.ini
				FileSetAttrib, +ASH, %A_LoopFileLongPath%\Desktop.ini
				FileSetAttrib, +S, %A_LoopFileLongPath%

		If (status = "not empty")
	
			FileDelete, %A_LoopFileLongPath%\desktop.ini

		Sleep, 100
      		ToolTip	
		}
    	Return


countFiles(Path) {
    i = 0
    Loop, % Path "\*.*", 0, 1
      i := (A_LoopFileExt = "ini") ? i : i += 1
    Return % i
    }
Other good idea, i don't know if will try it now or not, is to refresh folder icon preview every time the script get executed, because sometime it take time to show the new icon, i have no idea how windows 10 refresh his icon preview ! It can be very comfortable if we can see in real time the icon change.
sometime only half of icon change instantly and you've to wait 10/15s to the other folder to show the new icon even if the icon is already replaced.
But its optional so i have time to think about it !

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: jeves, mikeyww, septrinus and 292 guests