Page 1 of 2

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

Posted: 19 May 2017, 05:48
by a_God_Rabbit
Hello ! I'll kill me soon if i cannot end this script so i'm finally asking some help about some tips.
Sorry if my english is bad !!!! :roll:
Days and nights i'm trying to find a solution !!! :shock:

We are working in a huge tree structure with thousand of empty folder to start.....
Then we fill them little by little for month.
So it can be hard to find some file when people are working bad or just when we don't know if the file already exist or not.

What i'm looking for : Creating a script that check a master folder and all of his sub folder and turn all empty folder into red and not empty folder into normal state, every minute or when the user press a key to refresh color, i still don't know.

The idea : all folder start in red, then the color of the folder and his parent folder change when a user put a file into it

My first script :
Spoiler
This work well but change the name of the folder instead of his color. It was the first idea, but icon color is a much more better idea.
But it's still have bug because sometime it doesn't work, i don't know how to just rename a folder so i have to cut/past the folder and rename the new folder so it fail sometime.....and i can even loose file into the new folder or having a fail renaming..... I cannot take risk in a very huge project with thousand of file and sometime more than 1To file ++++. I don't like the idea of cut/past, and if someone is working in a file, we cannot cut/past etc.....

The 2nd script
Spoiler
Now it's the same but with icon color instead of rename. The loop i'm using to check all folder and subfolder is working very well with renaming but not with color folder because of the desktop.ici file generated.......

My loop is cheking folder size, if size = 0 it change the folder color, if > 0 i turn it back to normal state.
So now it's working on all sub folder but not parent folder ! because the desktop.ini file have a size and the folder isn't considered as empty after the creation of the desktop.ini !!!

So what i'm looking for is a way to ignore desktop.ini in the loop !! I have no idea how yo change folder color not using desktop.ini....
The loop is working fine, the icon color change too, but not together ....

So my solution would be :

- Ignore desktop.ini file size in the loop ??
- Instead of checking folder size to change color, check number of file into the folder + sub folder excluding .ini extension file ?????
and change color if number of file = 0 etc....
- have you an other idea ????!!

Thk you if you can find a solution for me ! and if you can check if my script is well done ( bug, optimization etc...) i'm not a ahk scripter so it's totally new for me, and check if its secure and safe to use.
and if you want you can help me to instead of choosing the folder, make it always working and we just have to press something like F12 key to execute the script once. I don't think it's a good idea to make it running every 30s or something like this....

Remember that it's to use in a very big tree structure, and it should be fast and safe.
I've tryied a lot of software to do it but all of the software isn't automatized...always have to change folder icon by hand one by one.....
and if you copy/past the folder it loose the color....
And only folder marker that isn't free allow you to work with folder + sub folder color change. it's the best i've find but still not that good/fast and 30$/computer is hard when we have more than 10 computer here.......
here you can copy/past execute the script and recover your folder color :)


THK You for saving my life !!!!!!!!! ;) I hope this script can help several person too !! it's really useful

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

Posted: 19 May 2017, 07:01
by BoBo
Click [here].
Based on its outcome you can start to think about cosmetics like that red/green-thing :silent:
I'd prefer to rename the folders/directories instead of changing its icons _Folder (that contains a file) vs Folder (empty).
But that shouldn't be necessary if you do it like this ...

[brainfart]
Keyword sharing violations: you could create an "inbox"-directory where people drop their files (well, its filenames have to follow a specification, so your process is able to assign/move a file to the correct directory), means they don't access those (sub)directories themselves.
Existing files will be read-only > FileGetAttrib/FileSetAttrib.
To hand over an already existing file will overwrite the previous copy.
To delete an already existing file it needs to hand over a copy of the existing file named eg. "delete_<existing filename>", that way you should have full control of the process and what happens within the folder structure. And of course, your process will log all of those requests for maintenance reasons!
[/brainfart]

Good luck! :)

PS. Regarding the desktop.ini-file - it might be possible to label it as a system file (FileSetAttrib). Probably it will be ignored that way?!

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

Posted: 19 May 2017, 08:19
by a_God_Rabbit
Thk you for your answer,

unfortunately desktop.ini isn't ignored in folder size even in system with (FileSetAttrib) hidden and system or more :(

In fact red / green isn't that good, but red/normal is okey, I've already working like this alone with software,
but i cannot use software to work like this at office with several employee, I've to automate this.
I can even change the icon to make it more unostentatious if not comfortable.

I'll work on it tonight on it ! thk you

edit : i'll check for disk usage tonight, it can be interesting, what is it ? it add function into ahk ?

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

Posted: 19 May 2017, 09:46
by BoBo
I don't understand the need for that INI-file? Why not keep all detected empty folders in an array, and all others in another array and do the red/green/black-icon cosmetics afterwards based on that?!

Just for the records/crowd [Dir], part of the TCC/-LE alias Take Command.

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

Posted: 19 May 2017, 11:07
by a_God_Rabbit
Because it's not for a unique use but the script will be executed a lot of time on the same folder.
So if i do like you said, it will probably work perfectly the first time but not the 2nd 3rd etc.....
Because all empty folder will not be empty anymore because of the ini file....i have no idea how can i change folder icon color without putting an ini file in it ...

ether i don't use ini and i find an other way to do what i want, or the script should work even if all file have an ini in it :/

an other way is to work with rename but i'm afraid it can cause trouble while working. ( renaming folder when people are working on file in it etc...)

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

Posted: 19 May 2017, 11:14
by a_God_Rabbit
In my opinion the best choice i have is to create a loop that list all file in a folder in an array and exclude all .ini from it,

if the number of total file - the number of .ini file = 0 ==> execute
else ==> execute other thing

If someone can help me to write this loop ?
Maybe it's more easier to work with file count than file size ?
Maybe i cannot do what i want XD :( !

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

Posted: 19 May 2017, 15:21
by BoBo
a_God_Rabbit wrote:In my opinion the best choice i have is to create a loop that list all file in a folder in an array and exclude all .ini from it,

if the number of total file - the number of .ini file = 0 ==> execute
else ==> execute other thing

If someone can help me to write this loop ?
Maybe it's more easier to work with file count than file size ?
Maybe i cannot do what i want XD :( !
Let's have a look ...
This command Run, cmd / k dir %USERPROFILE%\desktop\_Autohotkey\*.* /S /O:G /B /N
... has generated this output:

Code: Select all

C:\Users\User\desktop\_Autohotkey\Extras\Tools\WinSpy\Constants
C:\Users\User\desktop\_Autohotkey\Extras\Tools\WinSpy\Resources
C:\Users\User\desktop\_Autohotkey\Extras\Tools\WinSpy\WinSpy-x86.exe
C:\Users\User\desktop\_Autohotkey\Extras\Tools\WinSpy\WinSpy.ahk
C:\Users\User\desktop\_Autohotkey\Extras\Tools\WinSpy\WinSpy.ini
C:\Users\User\desktop\_Autohotkey\Extras\Tools\WinSpy\WinSpy-x64.exe
C:\Users\User\desktop\_Autohotkey\Extras\Tools\WinSpy\Constants\Styles.ini
C:\Users\User\desktop\_Autohotkey\Extras\Tools\WinSpy\Constants\Messages.ini
C:\Users\User\desktop\_Autohotkey\Extras\Tools\WinSpy\Resources\CrossHair.cur
C:\Users\User\desktop\_Autohotkey\Extras\Tools\WinSpy\Resources\FindTool1.bmp
C:\Users\User\desktop\_Autohotkey\Extras\Tools\WinSpy\Resources\FindTool2.bmp
C:\Users\User\desktop\_Autohotkey\Extras\Tools\WinSpy\Resources\Search.ico
C:\Users\User\desktop\_Autohotkey\Extras\Tools\WinSpy\Resources\Settings.ico
C:\Users\User\desktop\_Autohotkey\Extras\Tools\WinSpy\Resources\TreeIcons.icl
C:\Users\User\desktop\_Autohotkey\Extras\Tools\WinSpy\Resources\WinSpy.ico
... let's guess that any line/path that ends with showing a file extension isn't an empty folder (we're not on Unix/Linux, right!)

So you're focusing now on those and toggle the folders icon at whatever level up that tree/path.
In general, you've got the problem that one second after your processing someone can drop a file to that previously empty folder, means that changed icon will indicate a wrong status. For that reason, I've recommended a gateway/inbox where you can control incoming/outgoing data.

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

Posted: 19 May 2017, 16:37
by BoBo

Code: Select all

#SingleInstance, Force

!f::																		; press Alt+f
    myRootFolder := "<my root path here>"									; you've to change this accordingly 

    Loop, % myRootFolder "\*.*", 2											; check for subfolders at the next tree level
    {
      status := (countFiles(A_LoopFileFullPath)=0) ? "empty" : "not empty"	; check if that subfolder contains any files at whatever (sub)level and create a status msg
      ToolTip % A_LoopFileName " is " status								; only for testing
      If (status = "empty")													; because no file has been found ...
          ; <toggle icon of> A_LoopFileName									; do whatever you like eg. toogle the subfolders icon
      Sleep, 800															; only for testing
      ToolTip																; only for testing
      }
    Return

countFiles(Path) {															; count all files within the subfolder at whatever sublevel
    i = 0
    Loop, % Path "\*.*", 0, 1
      i++
      Return % i
      }
Hope that helps :)

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

Posted: 19 May 2017, 17:29
by a_God_Rabbit
It look very interesting ! I can't take a loot at it tonight but i'll go to office tomorrow to try it ! Thk you very much and i'll tell you if i can use it in any away :) !

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

Posted: 21 May 2017, 10:51
by a_God_Rabbit
Hello ! i'm working on this script again today, so according to your help I've change my script and it work very well !!
Now to end it i've to resolve the .ini problem.
i had to change some things to make it work. It run very fast !
So When i execute it with alt+f it change all folder icon well, then if i alt+f again it remove all icon folder change because of detecting a .ini in all file etc......
But i mean it's working ! Last thing to do now is to find a way of remove all .ini from the countFiles function but i think it's possible so i have a lot of hope !

Now i'll check what you mean about gateway/inbox and other thing you suggested because i still don't understand what it mean, i've to search what it is !

Here is the script
Spoiler

maybe in this line we can exclude desktop.ini, i'll try to find

Code: Select all

Loop, % Path "\*.*", 0, 1

PS : Yes we're working on windows 10

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

Posted: 21 May 2017, 14:01
by a_God_Rabbit
I tried a lot of code but still not working :/

This work well to ignore .ini but work only for .jpg and i can't write all ext we're using....
Spoiler
I tried something like this but i don't know how to make it work :/
Spoiler
or
Spoiler
Spoiler

even
Spoiler
and more................

Can someone help me to make this work ?
Just a simple loop reading all file in a folder and add +1 to %i for each file except .ini file ?

Thk you very much it's the end of my pain xD !!!

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

Posted: 21 May 2017, 14:26
by BoBo
One reason why I've preferred that approach was NOT to use/create an ini at all!
AFAICS the ini was meant to keep the information that that specific folder should have its icon swapped. Shouldn't be necessary anymore, please confirm?

Now i'll check what you mean about gateway/inbox and other thing you suggested because i still don't understand what it mean, i've to search what it is !
OK, let's have a try ...
a) one of your colleagues wants to drop/archive a file at a specific folder that has been assigned to him/her ...
...and let's say the company uses individual IDs for every employee (eg the login ID > A_Username)

b) OK, now you have to make it mandatory that all users drop their files into a specific shared folder (the "inbox")

c) ... and those files have to be created with a prefix following a mandatory file spec(ification). eg. ADD_%A_Username%_<yada yada>.docx

d) your process (nickname "Concierge") will parse that folder every 5 secs.

e) once it has identified an incoming file the process will extract from its filename ...
  • "ADD" (the "action type" here, the file should be added to the folder),
    "Username" (the destination, here: the file should be moved to the folder that is named that way).
    PS. nevertheless, the user should have read-access to that/his/her folder!
... and yes, it's up to you if you trim that prefix before you move the file to that final destination folder.

f) ... and of course it's nice if you create a log file for a later review if necessary/requested.

Well, as said the user has only read access to that folder so he/she can make a copy for further updates, but he/she won't be able to replace that file at its destination without handing it over via the "inbox" means to follow the standard procedure!

OK ok, what if the user wants to eliminate/remove that file?
E-a-s-y !! DEL_%Username%_<yada yada>.docx will do the trick.

If you think that's kinda noob-ish approach to deal/control with incoming data.
I had to support exactly such a (billing/provisioning) process 24/7 for > 10 years for one of the biggest telcos on this planet.

PS. save your a.. and ensure that your user's destination folders are getting backed up routinely !!!!
You should be able to restore that environment if it gets f... up for whatever reason :thumbup:

Code: Select all

ADD_GodRabbit_Trumponomics.docx > Inbox > process will ADD the file "Trumponomics.docx" to the folder "GodRabbit" and log that event at a logfile.
DEL_GodRabbit_Trumponomics.docx > Inbox > process will DEL(ete) the file "Trumponomics.docx" from the folder "GodRabbit" and log that event within its logfile.
Hope that helps :)

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

Posted: 21 May 2017, 15:01
by a_God_Rabbit
woaw, my problem is that i have no idea how to change folder icon/color without desktop.ini :/

But have in mind that i'm not a script killer xD i'm just a simple employee, and my job is to do visual effect in movie, i'm just doing this in my free time to help this small society and myself to not spend 10 year when i'm looking for a specific file in 1000+ folder xD ( one file lost between 10000 empty folder)

This gateway/inbox seem very very complicated for me and i don't think i can convince my society to work with it, and change the actual organisation,
and i don't think i have the skill to do this because coding is not my job xD I'm just trying to create a small tool of color.

We always have to create a lot of folder everywhere / file rename replace move everywhere, and it's different in every project, everybody have to be able to create or having control on everything and naming object as they want.

And i don't think that's noob ish approach at all but it's too complicated for us and we cannot work like this, my boss will refuse for sure, whereas having automatic color in folder, i think they can agree with this idea.

i'm learning ahk only to do this script. In fact i work only with python/mel because our software work with python :/

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

Posted: 21 May 2017, 15:11
by a_God_Rabbit
What i like with desktop.ini is that i don't have to modify folder/file or change something, only creating and deleting desktop.ini is perfect because if my script cause trouble and we loose file / folder it can fuck the project so hard and cause bankrupt xD ofc i'll get fired loool !!
That is why i don't want to change anything in our pipeline because i'm a beginner, the script have to be 100% safe and 0 risk !

i'll be sooo grateful if i can just have this script work :) everybody just have to press a button every time they add a file in a red folder is already so perfect , or i make this script run every 5 min or something like that so that nobody have nothing to do. Everybody here is very lazy .... T_T

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

Posted: 21 May 2017, 15:15
by a_God_Rabbit
Spoiler
i've absolutely no idea why this isn't working :/ !!
When i MsBox A_LoopFileExt, i really have ini / jpg /ahk etc..... in output

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

Posted: 21 May 2017, 16:06
by BoBo

Code: Select all

countFiles(Path) {										
    i = 0
    Loop, % Path "\*.*", 0, 1
      i := (A_LoopFileExt = "ini") ? i : i++
      Return % i
      }
     
:?: :?: :?:

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

Posted: 21 May 2017, 19:18
by a_God_Rabbit
it's really strange :/ i tested because it's really greatly wrote but still don't work :/ but it look so OK i don't understand !!!
The result is I = 0 even if folder are not empty !
and if i try i=1 all folder are not empty ! but they are all empty ! and if i remove i = 0, all folder are not empty so i = 1 oO .... but folder are really empty

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

Posted: 21 May 2017, 19:23
by a_God_Rabbit
maybe i have to create 2 loop if i can't with only one ....
A with Path "\*.*"
B with Path "\*.ini"
and Return A - B ? XD

Because until now only precise the extension in the path seem working :/

Code: Select all

countFiles(Path) {
	a = 0
	b = 0
    Loop, % Path "\*.ini", 0, 1
    	a++
    Loop, % Path "\*.*", 0, 1
    	b++
    return b - a 
    }
F*** !! I'm tired and so dead now but before going to bed still wanted to test this and it work so well !!! I'll try in more complex folder and seriously tomorrow but this seem to work very well !!!
Maybe we can write it better because i did it fast just to test but i'll be glad if we can write it better ! If everything work well i'll post the whole script !!

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

Posted: 22 May 2017, 02:04
by BoBo

Code: Select all

countFiles(Path) {
    i = 0
    Loop, % Path "\*.*", 0, 1
      i := (A_LoopFileExt = "ini") ? i : i += 1
    Return % i
    }
That one has worked fine for me. It doesn't count/ignores existing ini-files.*

Somebody in here might be able to point out a method (COM, dll, ...) to change a folders icon on the fly without using [this] but something like [that] and/or [that] ?!!

Just for the records, with AHK "Basic" (1.0.x) the expected ...
i := (A_LoopFileExt = "ini") ? i : i++ didn't work

...while
i := (A_LoopFileExt = "ini") ? i : i += 1 did.

* In general, to label a folder as empty while it is in fact not empty will spread confusion, minimum with those who have to deal with it once you've gone.

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

Posted: 22 May 2017, 04:17
by a_God_Rabbit
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 !