Help with the way to think about this - Taking a variable from somewhere inserting it into filename

Get help with using AutoHotkey and its commands and hotkeys
Johana
Posts: 189
Joined: 02 May 2017, 02:34

Help with the way to think about this - Taking a variable from somewhere inserting it into filename

13 Mar 2018, 08:34

I have a script today that outputs a file when being run. The file is for statistic purpose, so it outputs: Scriptrun_user_date_count.txt. Count = How many times a script has been run.

Today we found out that two new shelters are opening nearby and they would like to use the scripts we have as well. But we want to seperate the statistics. Here is how the architechture looks like:

Menu -that shows 20 scripts

Each script there's a Write statisticsfunction after "submit".
The function for the statistics are inside a file called functions.ahk that's #included in each script.
-------------

Here's my thought, maybe there's better and that I would like to know:
The menu get's installed by a simple "installation" ahk which basically puts the menu in a users autostart. The idea now is that when they press it, a gui popup where they can select their city.
Then it get's installed and a Cityname.ini (or .txt) file will be created and stored locally.

My thought is that the statistic code will read the filename and insert it into the path So i.e: Scriptrun_user_date_CITYNAME_count.txt.

Is there a better way? Here is my current stats code:

Code: Select all

WriteStatistic()
{
	FormatTime, DDay, %Dday%, yyyyMM
	NetworkFolder   := "Z:\AutoHotkey\Scripts\statistics" 
	ThisScript      := RegExReplace(A_ScriptName, "iDU)^(.*)\.(ahk|exe)$", "$1")
	
if fileexist(NetworkFolder "\" ThisScript "_" A_UserName "_" Dday "*") {
   loop, % NetworkFolder "\" ThisScript "_" A_UserName "_" Dday "*" {   
      RegExMatch(A_LoopFileName, "O)(.*)_(\d+)\.txt",tmp)      
      newName := NetworkFolder "\" tmp[1] "_" format("{:04}",tmp[2] + 1) ".txt"
      FileMove, % NetworkFolder "\" A_LoopFileName , % newName      
      FileAppend, % a_now "`n", % newName 
   }
} else {
   FileAppend, % a_now "`n", % NetworkFolder "\" ThisScript "_" A_UserName "_" dday "_" format("{:04}",1) ".txt"
}   
return
} 
MaxAstro
Posts: 557
Joined: 05 Oct 2016, 13:00

Re: Help with the way to think about this - Taking a variable from somewhere inserting it into filename

13 Mar 2018, 08:54

One comment I will make is that seems like a lot of relatively empty text files, which seems like an organizational mess. Any reason not to use a smaller set of ini files instead? For example, you could have an ini file for each script with sections for each user, and then the key-value pairs could be the date and count. That seems like it would make it a lot easier to see at a glance how often specific scripts are being run.
BoBo
Posts: 3869
Joined: 13 May 2014, 17:15

Re: Help with the way to think about this - Taking a variable from somewhere inserting it into filename

13 Mar 2018, 09:49

The menu get's installed by a simple "installation" ahk which basically puts the menu in a users autostart. The idea now is that when they press it, a gui popup where they can select their city.
I'd try to identify the location using a less error-prone option eg via the box's ID/owner (your IT is keeping an up2date local-centric inventory list, right?)
Then it get's installed and a Cityname.ini (or .txt) file will be created and stored locally.
I'd check if your IT/HR is using a specific internal code assigned to a location. That city option is human-friendly but what once there is another city with the same name (Frankfurt/Main,Frankfurt/Oder,...), so the post-/zipcode would be more specific. Think big(ger) ;)

@MaxAstro
I would not go with INIfiles those aren't made to keep archived data/values of previous sessions (for further processing/reporting). CSV (poor man's database) or whatever DB should make it :)

Return to “Ask For Help”

Who is online

Users browsing this forum: Daily the Noob, Woolley89 and 51 guests