It is currently April 28th, 2024, 1:06 pm

Load file to display from a folder

Get help with installing and using Rainmeter.
lionpack
Posts: 11
Joined: July 27th, 2023, 8:25 pm

Load file to display from a folder

Post by lionpack »

Hi,

I have numbered text files in a folder, I would like to display the content of each text file one file at a time in order that the files are numbered.

Ex:
1.txt
2.txt
3.txt

How can I do that?

Thank you!
User avatar
balala
Rainmeter Sage
Posts: 16183
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Load file to display from a folder

Post by balala »

lionpack wrote: July 27th, 2023, 8:32 pm How can I do that?
Using a WebParser measure for instance. Here is a short example on how this could be done:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1

[Variables]
Num=1
MaxNum=3

[MeasureFile]
Measure=WebParser
URL=file://#@##Num#.txt
RegExp=(?siU)^(.*)$
StringIndex=1
DynamicVariables=1

[MeterFile]
Meter=STRING
MeasureName=MeasureFile
X=0
Y=0
Padding=15,5,15,5
FontColor=220,220,220
FontEffectColor=0,0,0
StringEffect=Shadow
SolidColor=0,0,0,150
FontSize=8
FontFace=Segoe UI
StringStyle=BOLD
StringAlign=LEFT
AntiAlias=1
Text=#Num##CRLF#----------#CRLF#%1
DynamicVariables=1
LeftMouseUpAction=[!SetVariable Num "((#Num#=#MaxNum#)?1:(#Num#+1))"][!UpdateMeasure "MeasureFile"][!CommandMeasure "MeasureFile" "Update"]
Note the followings:
  • You have to have the numbered files into the @Resources folder. Obviously you can change the path into the URL option of the [MeasureFile] measure.
  • Set the number of files you have as the MaxNum variable, into the [Variables] section.
  • You didn't said when would you like to switch to the next file. I did it by a click: when you click the shown file content (to the [MeterFile] meter in fact), the skin switches to the next file. Keep in mind that it needs a little bit time to the WebParser measure can read the content of next file.
If there are some other things I didn't take into account, please let me know. also let me know if the code works as you expect.
lionpack
Posts: 11
Joined: July 27th, 2023, 8:25 pm

Re: Load file to display from a folder

Post by lionpack »

Hi,

If the files are numbered like the following it's not working:
001-001
001-002

Also can you please display the following on the bottom:
Text=#Num##CRLF#----------#CRLF#%1

Click for switching is good, can you please also make it update every few minutes.

Thank you for your help!
User avatar
SilverAzide
Rainmeter Sage
Posts: 2613
Joined: March 23rd, 2015, 5:26 pm

Re: Load file to display from a folder

Post by SilverAzide »

lionpack wrote: July 28th, 2023, 2:11 am
Sorry, no one is going to do this for you. Balala has already done all the hard work for you, you need to finish this yourself. Please read the policy on skin requests. We will be glad to help YOU create the skin, but don't expect others to do it.
Gadgets Wiki GitHub More Gadgets...
User avatar
Yincognito
Rainmeter Sage
Posts: 7179
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Load file to display from a folder

Post by Yincognito »

lionpack wrote: July 28th, 2023, 2:11 amIf the files are numbered like the following it's not working:
001-001
001-002
Of course it won't work, because the above was tailored for your initial objective. If you change the parameters of that objective and expect it to automagically work, it won't happen. To make it work (which will mean that your initial 1, 2, 3 will cease to work as well), you'll need to:
- create a String measure like in the example here, placed before [MeasureFile]
- use #Num# as the String value in that measure, and turn it to the format you need via a regular expression (regexp) Substitute like in the example
- add DynamicVariables=1 in this measure, so that the current values of variables are "seen" by it
The Substitute will need to be something like Substitute="^(.+)$":"00\1","^.*(.{3})$":"001-\1" in order to add sufficient zeros before the number, then remove the extra zeros and precede things with 001- as it looks from your list above. The final steps would be to:
- use the newly created measure (its name preceded by [& and followed by ], see here why) instead of #Num# in the URL option of [MeasureFile]
- make sure you update this new measure before updating [MeasureFile] in the LeftMouseUpAction from your meter
lionpack wrote: July 28th, 2023, 2:11 amdisplay the following on the bottom:
Text=#Num##CRLF#----------#CRLF#%1
Not sure what you mean here, but if you want the number to be displayed below (instead of above) the file contents, it's simply a matter of switching #Num# and %1 in the said Text option.
lionpack wrote: July 28th, 2023, 2:11 amClick for switching is good, can you please also make it update every few minutes.
The simplest way to do this would be to add a suitable UpdateDivider to your meter, and an OnUpdateAction where you copy paste the same bangs from your LeftMouseUpAction (i.e. what's after = on that line). The safest way to do it would be to create a dummy measure (say, a Calc one) where you'd add the said UpdateDivider and OnUpdateAction, as well as a DynamicVariables=1 for the reason explained above.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
balala
Rainmeter Sage
Posts: 16183
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Load file to display from a folder

Post by balala »

SilverAzide is perfectly right above, we usually help folks out there to write their own codes. So would be nice if you'd try out few things.
lionpack wrote: July 28th, 2023, 2:11 am Also can you please display the following on the bottom:
Text=#Num##CRLF#----------#CRLF#%1
Same way as Yincognito, I'm not sure what do you mean by this either? This option is the one I added to the [MeterFile] meter. What you want to do with this, because it is displayed. So, can't follow you...
lionpack wrote: July 28th, 2023, 2:11 am If the files are numbered like the following it's not working:
001-001
001-002
If you have not more than 9 files (from 001.txt to 009.txt) this is easy. Guess how? By adding the double 0 before the #Num#.txt file name, in the URL option of the [MeasureFile] measure: URL=file://#@#00#Num#.txt.
If there are more files and you have files having two 0s and others having one single, the things are little bit more complicated, but not impossible to solve. So, how many files do you have?
lionpack wrote: July 28th, 2023, 2:11 am Click for switching is good, can you please also make it update every few minutes.
See Yincognito's reply above. I'd do this by a simple Calc measure. Add one to your code. For instance something like this:

Code: Select all

[MeasureNum]
Measure=Calc
Formula=(( MeasureNum = #MaxNum# ) ? 1 : ( MeasureNum + 1 ))
UpdateDivider=60
See the most important option here: UpdateDivider. It is meant to set the frequency at which the measure is updated. If in the [Rainmeter] section the Update is set to the default Update=1000 (as I posted in my code above), the skin is updated once per 1000 milliseconds = 1 per second. Adding an UpdateDivder=60 option to the measure means it is updated once per 60 seconds (so once at each 60th update of the skin). This means that the value of the measure is changing between 1 and #MaxNum#, once per 60 seconds. You can use this slowly varying value into the URL option of the [MeasureFile] measure, instead of the #Num# variable: URL=file://#@#[MeasureFile].txt. But if there is no click, you have to make sure the [MeasureFile] measure is updated on every update (so value change) of the [MeasureNum] measure. How can you do this? By adding an OnChangeAction option to the [MeasureNum] measure, which updates the [MeasureFile] measure on every change of the [MeasureNum] measure. This option should contains the same bangs as the LeftMouseUpAction option of the [MeterFile] meter, excepting the first !SetVariable bang (because in this case, there is no Num variable anymore): OnChangeAction=[!UpdateMeasure "MeasureFile"][!CommandMeasure "MeasureFile" "Update"]. The !UpdateMeasure bangs updates the [MeasureFile] measure, by setting the just-got, new value of the measure, while the !CommandMeasure bang updates the same [MeasureFile] measure into a different way, by sending it to immediately read the information contained into the new .txt file.
There are solutions to use both: the once-per-60secs update and the update done by click. However for first I recommend not to complicate things too much. Try out what I described above and let me know if there is something you didn't get.
Did you succeed in getting the new code working?
lionpack
Posts: 11
Joined: July 27th, 2023, 8:25 pm

Re: Load file to display from a folder

Post by lionpack »

There are 1000+ files named in the following format:

001-000
001-001
001-002
001-003
...
002-000
002-001
002-002
...
003-000
003-001
003-002
...

Thank you for your help!
User avatar
Yincognito
Rainmeter Sage
Posts: 7179
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Load file to display from a folder

Post by Yincognito »

lionpack wrote: July 28th, 2023, 6:06 pm There are 1000+ files named in the following format:

001-000
001-001
001-002
001-003
...
002-000
002-001
002-002
...
003-000
003-001
003-002
...
How many of the 001-..., 002-..., 003-... files do you have in each "set"? Do they follow a certain logic or their number is arbitrary? Because if it's the latter, a better choice would be to just mass rename them in a consistent fashion, e.g. 0001 to 1000+ and such (there are free tools that can do that) and simplify the problem.

P.S. You keep changing key details of the scenario as we progress: first, numbers started from 1, now they're starting from 0. So, which one is it? Also, did you try any of the approaches above?
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
balala
Rainmeter Sage
Posts: 16183
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Load file to display from a folder

Post by balala »

Apart from Yincognito's recommendation, if that's not possible here is a workaround:
lionpack wrote: July 28th, 2023, 6:06 pm There are 1000+ files named in the following format:
In this case you need two Calc measure, I think. One for the first element of the names, another for the second one. Add them (in fact replace [MeasureNum] by these ones):

Code: Select all

[MeasureNum1]
Measure=Calc
Formula=(( MeasureNum1 = #MaxNum1# ) ? 1 : ( MeasureNum1 + 1 ))
RegExpSubstitute=1
Substitute="^(\d{1})$":"00\1","^(\d{2})$":"0\1"
UpdateDivider=-1

[MeasureNum2]
Measure=Calc
Formula=(( MeasureNum2 = #MaxNum2# ) ? 1 : ( MeasureNum2 + 1 ))
IfCondition=(#CURRENTSECTION#=1)
IfTrueAction=[!UpdateMeasure "MeasureNum1"]
RegExpSubstitute=1
Substitute="^(\d{1})$":"00\1","^(\d{2})$":"0\1"
OnChangeAction=[!UpdateMeasure "MeasureFile"][!CommandMeasure "MeasureFile" "Update"]
UpdateDivider=60
In order these measures to work properly, you have to replace the MaxNum variable in the [Variables] section by MaxNum1 and MaxNum2, which are the largest values of the first, respectively the second part of the names (the one before, respectively after the - character).
A few things to take into account:
  • The second measure ([MeasureNum2]) is updated once per minute (in fact once per 60 seconds), due to its UpdateDivider=60 option. The first measure ([MeasureNum1]) is never updated, having the UpdateDivider=-1 option. A negative value for the UpdateDivider options means the measure is never updated, excepting the very first moment after the refresh. However even this measure has to be updated sometimes. These updates are done when [MeasureNum2] gets "restarted" (so when its value is set to 1), by the IfTrueAction option of the [MeasureNum2] measure. In this moment the IfTrueAction is executed, updating the [MeasureNum1] measure. This way the value of [MeasureNum1] is updated when it has to be, so when the [MeasureNum2] measure is "restarted".
  • I added to both measures a RegExpSubstitute=1 and a Substitute="^(\d{1})$":"00\1","^(\d{2})$":"0\1" option. These options adds the appropriate number of 0s before the numbers, in a way to always got three digits. In the Substitute option, (\d{1}) means the expression of the measure is composed by one single digit, while obviously (\d{2}) means there are two digits. In both cases the appropriate number of 0s are added.
  • This time the OnUpdateAction option has been added to the second measure ([MeasureNum2]), to get the [MeasureFile] measure updated on each change of the value of the second file (the one to which the option has been added), to get read the appropriate file on each change of the measure (this being the measure changing more frequently). The added OnChangeAction option is the same as previously, so hope it doesn't need explanation.
Having these measures, replace the URL option of the [MeasureFile] measure with this: URL=file://#@#[MeasureNum1]-[MeasureNum2].txt.

Does this code works?
User avatar
Yincognito
Rainmeter Sage
Posts: 7179
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Load file to display from a folder

Post by Yincognito »

balala wrote: July 28th, 2023, 6:52 pmIn this case you need two Calc measure, I think. One for the first element of the names, another for the second one.
Just a small note: this will work only if there are equal numbers of 001-..., 002-... and 003-... in their respective sets (hence my question about the logic of their amount), because otherwise you'd have different #MaxNum2# values depending on which set the file belongs to (001-, 002- or 003-) and things will complicate really fast. Besides that, it appears that now the numerical part after the - starts from 0 and not 1 according to the OP, which, as you surely know, would probably involve some disabling and enabling of various measures (or, if things are relatively simple and don't involve dynamic change, using Loop measures instead, which would simplify things in a way).
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth