It is currently December 12th, 2019, 8:27 pm

Rename file

Get help with installing and using Rainmeter.
User avatar
eclectic-tech
Rainmeter Sage
Posts: 3643
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: Rename file

eclectic-tech » November 25th, 2019, 8:40 pm

Even with adding 'DynamicVariables=1' to the measure, you have the problem:

When you run the "rename" command "MyFile.ini" NO LONGER EXISTS, you renamed it to "MyFile2.ini"
That is why it only works once. :uhuh:

I would need to know what it is you hope to accomplish by renaming the file?

"Copy" or "Xcopy" may be better choices based on what you need.

Code: Select all

[MeasureRun]
Measure=Plugin
Plugin=RunCommand
Parameter=copy /Y "#@#MyFile.ini" "MyFile#Num#.ini"
State=Hide
OutputType=ANSI
DynamicVariables=1
This will copy "MyFille.ini" as "MyFile2.ini", then if you increase #Num# to 3 and run the measure again, it will create "MyFile3.ini", etc. etc. The '/Y' tells the command not to prompt you about overwriting an existing file.
User avatar
balala
Rainmeter Sage
Posts: 9258
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Rename file

balala » November 25th, 2019, 8:45 pm

eclectic-tech wrote:
November 25th, 2019, 8:40 pm
When you run the "rename" command "MyFile.ini" NO LONGER EXISTS, you renamed it to "MyFile2.ini"
That is why it only works once. :uhuh:
Right. Stupid me, again missed this small detail.
Congratulations, good observation. :thumbup:
User avatar
Pul53dr1v3r
Posts: 316
Joined: July 30th, 2014, 10:30 am

Re: Rename file

Pul53dr1v3r » November 25th, 2019, 9:16 pm

in the meanwhile i've created a test skin with input text box.

Code: Select all

[Rainmeter]
Update=1000
AccurateText=1
MiddleMouseDownAction=[!Refresh]
OnRefreshAction=[!CommandMeasure "MeasureRun" "Run"]

[Variables]
@IncludeVariables=#@#Variables.inc

[meterBg]
Meter=Shape
Shape=Rectangle 0,0,250,50,5 | Fill Color 0,0,0

[StyleInputTxtBoxTo10_Set]
 Shape=Rectangle 0,0,25,16,4 | StrokeWidth 0.3 | StrokeColor 0,0,150 | Extend Fill
 Fill=Fill Color 255,255,255

 [StyleRightAlignBox_r_Set]
 StringAlign=Right
 X=(10-40)
 Y=-3r

 [StyleRightAlign_r_Set]
 StringAlign=Right
 X=10
 Y=r

[MeasureRun]
Measure=Plugin
Plugin=RunCommand
Parameter=rename "#@#MyFile.ini" "MyFile#Num#.ini"
State=Hide
OutputType=ANSI

 [InputTxtBoxMyFile]
 Measure=Plugin
 Plugin=InputText
 FontSize=10
 InputNumber=1
 InputLimit=2
 FocusDismiss=1
 X=[MyFile.Field:X]
 Y=[MyFile.Field:Y]
 W=[MyFile.Field:W]
 H=[MyFile.Field:H]
 DynamicVariables=1
 DefaultValue=#Num#
 Command1=[!WriteKeyValue Variables Num "$UserInput$" #@#Variables.inc]

[LabelMyFile]
 Meter=String
 FontColor=255,255,255
 X=10
 Y=10
 Text=FileNameSuffix:

[MyFile.Field]
 Meter=Shape
 MeterStyle=StyleInputTxtBoxTo10_Set | StyleRightAlignBox_r_Set
 X=5R
 Y=2r
 LeftMouseUpAction=[!SetVariable variableName #Num# #@#Variables.inc][!CommandMeasure InputTxtBoxMyFile "ExecuteBatch 1"]

 [ValueMyFile]
 Meter=String
 StringAlign=CenterCenter
 FontColor=255,0,0
 X=12r
 Y=8r
 Text=#Num#
Variables.inc

Code: Select all

[Variables]
Num=3
So the file name should be changed any time we change the value in the InputText box.

@ ET, right. That's what i was talking about. When we change it once, the file name doesn't exist anymore so we have to enter the new name in the code in order to change it again and so on. I planned to use it for "customized language" option. So when someone enters his language code, for example es-ES, the name (Variable) at the same time changes the file name suffix, link language (Link=https://weather.com/#Num#/weather/today/l/) and some option in measures. All at once. And if sb make a mistake entering the code, it shouldn't make a mess and stop him to enter a new one etc.
Last edited by Pul53dr1v3r on November 25th, 2019, 9:41 pm, edited 1 time in total.
User avatar
balala
Rainmeter Sage
Posts: 9258
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Rename file

balala » November 25th, 2019, 9:40 pm

Pul53dr1v3r wrote:
November 25th, 2019, 9:16 pm
@ ET, right. That's what i was talking about. When we change it once, the file name doesn't exist anymore so we have to enter the new name in the code in order to change it again and so on.
No, ET is right, you can't change the name of a nonexistent file. Once the skin refreshed / loaded, MyFile.ini is renamed as MyFileX.ini, so later you can't rename MyFile.ini again. There is nothing to be renamed, because MyFile.ini doesn't exist anymore, but [MeasureRun] wants to rename a such file (the first parameter of the rename command).
So although you're entering a valid number into the InputText field, [MeasureRun] doesn't have what to rename.
User avatar
Pul53dr1v3r
Posts: 316
Joined: July 30th, 2014, 10:30 am

Re: Rename file

Pul53dr1v3r » November 25th, 2019, 9:48 pm

balala wrote:
November 25th, 2019, 9:40 pm
No, ET is right, you can't change the name of a nonexistent file. Once the skin refreshed / loaded, MyFile.ini is renamed as MyFileX.ini, so later you can't rename MyFile.ini again. There is nothing to be renamed, because MyFile.ini doesn't exist anymore, but [MeasureRun] wants to rename a such file (the first parameter of the rename command).
So although you're entering a valid number into the InputText field, [MeasureRun] doesn't have what to rename.
yes, but as i wrote, if there is a way to retrieve the new file name and use it in the measure instead of the old one right after the change, it could be possible. But seems it isn't...
User avatar
eclectic-tech
Rainmeter Sage
Posts: 3643
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: Rename file

eclectic-tech » November 26th, 2019, 3:28 am

Intention;;Pul53dr1v3r;; I planned to use it for "customized language" option. So when someone enters his language code, for example es-ES, the name (Variable) at the same time changes the file name suffix, link language (Link=https://weather.com/#Num#/weather/today/l/) and some option in measures. All at once. And if (sb)somebody make a mistake entering the code, it shouldn't make a mess and stop him to enter a new one etc.
It seems that your method could be simplified if it's main purpose is to utilize different variables, measures, and meters to support languages.

To start, renaming a file will not allow you to use those item in your skin immediately; you MUST refresh the skin to use the renamed file.

Since you need to refresh after an end user selects his language (or you rename a file or you use !WriteKeyValue), why not just write a new #language# variable, and use "@includeLanguage=Lang#Language#.inc" in your skin. That file will include all the variables, measures and meters to support the selected language.

How does your end user know that he should enter a certain 'number' for his language?
Do you have a reference chart showing number for a language?

To me it is easler just to offer the available languages in a meter, that when clicked, sets the 'language' variable and refreshes.

Relying on the end user to manually enter a value and hope they don't enter something that crashes the skin seems like asking for trouble. :uhuh:

There are a number of skins that offer translated version, for example see Modules by Sephirotess, they may help you achieve translations.

Without seeing your entire skin with language options you want to implement, it is not possible to give you a solution. :Whistle
User avatar
Pul53dr1v3r
Posts: 316
Joined: July 30th, 2014, 10:30 am

Re: Rename file

Pul53dr1v3r » November 26th, 2019, 5:49 pm

eclectic-tech wrote:
November 26th, 2019, 3:28 am
i've been using the method you are talking about for some of the main languages but wished to implement it for a customized one. It could be any other language that doesn't exist in the list. i had an intention to make it as easy as possible to the Rainmeter beginners or others who come from different sides of the world and don't know any of the offered languages.
That way i've liked to avoid making a new file for the new language and forcing users to go to the skin files and to tussle with it there.
User avatar
balala
Rainmeter Sage
Posts: 9258
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Rename file

balala » November 26th, 2019, 6:32 pm

Pul53dr1v3r wrote:
November 25th, 2019, 9:48 pm
yes, but as i wrote, if there is a way to retrieve the new file name and use it in the measure instead of the old one right after the change, it could be possible. But seems it isn't...
But it definitely is:

Code: Select all

[Rainmeter]
Update=1000
AccurateText=1
MiddleMouseDownAction=[!Refresh]
OnRefreshAction=[!CommandMeasure "MeasureRun" "Run"]

[Variables]
@IncludeVariables=#@#Variables.inc

[meterBg]
Meter=Shape
Shape=Rectangle 0,0,250,50,5 | Fill Color 0,0,0

[StyleInputTxtBoxTo10_Set]
 Shape=Rectangle 0,0,25,16,4 | StrokeWidth 0.3 | StrokeColor 0,0,150 | Extend Fill
 Fill=Fill Color 255,255,255

 [StyleRightAlignBox_r_Set]
 StringAlign=Right
 X=(10-40)
 Y=-3r

 [StyleRightAlign_r_Set]
 StringAlign=Right
 X=10
 Y=r

[MeasureRun]
Measure=Plugin
Plugin=RunCommand
Parameter=rename "#@#MyFile#Old#.ini" "MyFile#Num#.ini"
State=Hide
OutputType=ANSI
FinishAction=[!SetVariable Old "#Num#"][!WriteKeyValue Variables Old "#Num#" "#@#Variables.inc"]
DynamicVariables=1

[InputTxtBoxMyFile]
Measure=Plugin
Plugin=InputText
FontSize=10
InputNumber=1
InputLimit=2
FocusDismiss=1
X=[MyFile.Field:X]
Y=[MyFile.Field:Y]
W=[MyFile.Field:W]
H=[MyFile.Field:H]
DynamicVariables=1
DefaultValue=#Num#
Command1=[!WriteKeyValue Variables Num "$UserInput$" "#@#Variables.inc"]
Command2=[!SetVariable Num "[InputTxtBoxMyFile]"]
DynamicVariables=1

[LabelMyFile]
Meter=String
FontColor=255,255,255
X=10
Y=10
Text=FileNameSuffix:

[MyFile.Field]
Meter=Shape
MeterStyle=StyleInputTxtBoxTo10_Set | StyleRightAlignBox_r_Set
X=5R
Y=2r
LeftMouseUpAction=[!SetVariable variableName #Num# #@#Variables.inc][!CommandMeasure InputTxtBoxMyFile "ExecuteBatch 1-2"]

[ValueMyFile]
Meter=String
StringAlign=CenterCenter
FontColor=255,0,0
X=12r
Y=8r
Text=#Num#
DynamicVariables=1
Variables.inc:

Code: Select all

[Variables]
Num=3
Old=3
User avatar
Pul53dr1v3r
Posts: 316
Joined: July 30th, 2014, 10:30 am

Re: Rename file

Pul53dr1v3r » November 26th, 2019, 7:08 pm

balala wrote:
November 26th, 2019, 6:32 pm
But it definitely is:

Code: Select all

[Rainmeter]
Update=1000
AccurateText=1
MiddleMouseDownAction=[!Refresh]
OnRefreshAction=[!CommandMeasure "MeasureRun" "Run"]

[Variables]
@IncludeVariables=#@#Variables.inc

[meterBg]
Meter=Shape
Shape=Rectangle 0,0,250,50,5 | Fill Color 0,0,0

[StyleInputTxtBoxTo10_Set]
 Shape=Rectangle 0,0,25,16,4 | StrokeWidth 0.3 | StrokeColor 0,0,150 | Extend Fill
 Fill=Fill Color 255,255,255

 [StyleRightAlignBox_r_Set]
 StringAlign=Right
 X=(10-40)
 Y=-3r

 [StyleRightAlign_r_Set]
 StringAlign=Right
 X=10
 Y=r

[MeasureRun]
Measure=Plugin
Plugin=RunCommand
Parameter=rename "#@#MyFile#Old#.ini" "MyFile#Num#.ini"
State=Hide
OutputType=ANSI
FinishAction=[!SetVariable Old "#Num#"][!WriteKeyValue Variables Old "#Num#" "#@#Variables.inc"]
DynamicVariables=1

[InputTxtBoxMyFile]
Measure=Plugin
Plugin=InputText
FontSize=10
InputNumber=1
InputLimit=2
FocusDismiss=1
X=[MyFile.Field:X]
Y=[MyFile.Field:Y]
W=[MyFile.Field:W]
H=[MyFile.Field:H]
DynamicVariables=1
DefaultValue=#Num#
Command1=[!WriteKeyValue Variables Num "$UserInput$" "#@#Variables.inc"]
Command2=[!SetVariable Num "[InputTxtBoxMyFile]"]
DynamicVariables=1

[LabelMyFile]
Meter=String
FontColor=255,255,255
X=10
Y=10
Text=FileNameSuffix:

[MyFile.Field]
Meter=Shape
MeterStyle=StyleInputTxtBoxTo10_Set | StyleRightAlignBox_r_Set
X=5R
Y=2r
LeftMouseUpAction=[!SetVariable variableName #Num# #@#Variables.inc][!CommandMeasure InputTxtBoxMyFile "ExecuteBatch 1-2"]

[ValueMyFile]
Meter=String
StringAlign=CenterCenter
FontColor=255,0,0
X=12r
Y=8r
Text=#Num#
DynamicVariables=1
Variables.inc:

Code: Select all

[Variables]
Num=3
Old=3
i tried sth very similar last night with 2 variables, but i used OnChangeAction instead of FinishAction.
Probably it wasn't the only mistake so it didn't work while this is working! :rosegift:
User avatar
balala
Rainmeter Sage
Posts: 9258
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Rename file

balala » November 26th, 2019, 7:11 pm

Pul53dr1v3r wrote:
November 26th, 2019, 7:08 pm
while this is working! :rosegift:
I'm glad. :thumbup: