It is currently April 24th, 2024, 5:00 am

How to extract file names

Get help with creating, editing & fixing problems with skins
gkmaz9
Posts: 67
Joined: August 26th, 2019, 10:42 am

How to extract file names

Post by gkmaz9 »

Part of the code for understanding

Code: Select all

[!WriteKeyValue "Variables" "Name" "$File$" "#@#variables.inc""]
I want to record the AAA.png(or CCC.jpg) in variables.inc

'$File$' extracts everything, including the path
ex) C:\sss\AAA.png

but I want to extract the file name including extension Except path.
ex) AAA.png

Please tell me a good way
Last edited by gkmaz9 on July 30th, 2020, 8:14 pm, edited 1 time in total.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: How to extract file names

Post by jsmorley »

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

[Variables]
MyVar=C:\sss\AAA.png

[MeasureFileName]
Measure=String
String=#MyVar#
RegExpSubstitute=1
Substitute=".*\\(.*)":"\1"

[MeterFileName]
Meter=String
MeasureName=MeasureFileName
FontSize=13
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1

1.jpg

The key to this is the String measure. You can use that as a [SectionVariable] anywhere you need, and it will return that substituted string value.
You do not have the required permissions to view the files attached to this post.
gkmaz9
Posts: 67
Joined: August 26th, 2019, 10:42 am

Re: How to extract file names

Post by gkmaz9 »

jsmorley wrote: July 30th, 2020, 5:44 pm

Code: Select all

[Variables]
MyVar=C:\sss\AAA.png

[MeasureFileName]
Measure=String
String=#MyVar#
RegExpSubstitute=1
Substitute=".*\\(.*)":"\1"


1.jpg


The key to this is the String measure. You can use that as a [SectionVariable] anywhere you need, and it will return that substituted string value.

Thank you for answer. However, it is a more special situation.
I am trying to extract the filename of 'drag and drop random file'.
and It should be written in [Variables]

main.ini

Code: Select all

[DragNDropChild1]
Measure=Plugin
Plugin=Drag&Drop
Parent=DragNDropParent
Bounds=Box1
Action=Path
OnOverAction=[!SetOption DragNDropChild1 OnDropAction """[!WriteKeyValue "Variables" "Name1" "C:\Users\USER\Documents\Rainmeter\Skins\Todo\Save\#YR##MT##DY#\$File$" "#@#log\#YR##MT##DY#.inc""][!Update]"""][!Update]
OnLeaveAction=[!SetOption DragNDropChild1 OnDropAction ""][!Update]
When I drag and drop the file(C:\Users\USER\Documents\DDD\AAA.png),
I want this result

#YR##MT##DY#.inc

Code: Select all

[Variables]
Name1=C:\Users\USER\Documents\Rainmeter\Skins\Todo\Save\#YR##MT##DY#\AAA.png

But the current result is...

#YR##MT##DY#.inc

Code: Select all

[Variables]
Name1=C:\Users\USER\Documents\Rainmeter\Skins\Todo\Save\#YR##MT##DY#\C:\Users\USER\Documents\DDD\AAA.png
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: How to extract file names

Post by jsmorley »

Well, I don't know anything about the Drag&Drop plugin, but explore something like this:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

[Variables]

[DragNDropChild1]
Measure=Plugin
Plugin=Drag&Drop
Parent=DragNDropParent
Bounds=Box1
Action=Path
OnOverAction=[!SetOption DragNDropChild1 OnDropAction """[!SetOption MeasureFileName String "[DragNDropChild1]"]"""][!Update]
OnLeaveAction=[!SetOption DragNDropChild1 OnDropAction ""][!Update]

[MeasureFileName]
Measure=String
RegExpSubstitute=1
Substitute=".*\\(.*)":"\1"
OnChangeAction=[!WriteKeyValue "Variables" "Name1" "C:\Users\USER\Documents\Rainmeter\Skins\Todo\Save\#YR##MT##DY#\[DragNDropChild1]" "#@#log\#YR##MT##DY#.inc""][!Update]

[MeterFileName]
Meter=String
MeasureName=MeasureFileName
FontSize=13
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
In any case, the key is getting the value of the path and filename of the file into a measure were you can extract just the filename using Substitute.
User avatar
Active Colors
Moderator
Posts: 1251
Joined: February 16th, 2012, 3:32 am
Location: Berlin, Germany

Re: How to extract file names

Post by Active Colors »

There is another tip about that posted by ~Faradey~ here: https://forum.rainmeter.net/viewtopic.php?t=9594
gkmaz9
Posts: 67
Joined: August 26th, 2019, 10:42 am

Re: How to extract file names

Post by gkmaz9 »

I found the answer by applying what you told me appropriately.
Thank you.

Code: Select all

[rainmeter]
Update=1000

[Variables]
@include=#@#Variables2.inc
YR=20
MT=07
DY=31
FFT=Open Sans Regular
CT=255,255,255,200

[Arrow]
Meter=Image
ImageName=#@#Images\Arrow.png
X=140
Y=2
W=20
H=20
LeftMouseDownAction=!Execute [!RainmeterHideMeter ArrowR]
LeftMouseUpAction=[!RainmeterShowMeter ArrowR][!WriteKeyValue Variables @include1 #@#Log\#YR##MT##DY#.inc #@#Variables2.inc][!WriteKeyValue Variables include1 #@#Log\#YR##MT##DY#.inc #@#Variables2.inc][!Refresh]
MouseOverAction=!Execute [!RainmeterShowMeter ArrowR][!RainmeterRedraw]
MouseLeaveAction=!Execute [!RainmeterHideMeter ArrowR][!RainmeterRedraw]

[ArrowR]
Meter=IMAGE
ImageName=#@#Images\Arrow.png
X=0r
Y=0r
W=20
H=20
ImageTint=0,0,0,95
Hidden=1

[YR_Write]
Measure=Plugin
Plugin=InputText
FontFace=#FFT#
W=30
H=20
X=0
Y=0
FontSize=14
SolidColor=200,200,200,255
FontColor=255,255,255
AntiAlias=1
ClipString=1
InlineSetting=CharacterSpacing | 2 | 2
DefaultValue=#YR#
Command1=[!WriteKeyValue "Variables" "YR" "$UserInput$"][!Refresh]
DynamicVariables=1

[YR_Record]
Meter=String
W=40
H=20
X=0
Y=0
FontSize=14
FontFace=#FFT#
FontColor=#CT#
SolidColor=200,200,200,1
DynamicVariables=1
Text=#YR#yr
LeftMouseUpAction=[!CommandMeasure "YR_Write" "ExecuteBatch 1"][!RainmeterRedraw]
Hidden=0

[MT_Write]
Measure=Plugin
Plugin=InputText
FontFace=#FFT#
W=30
H=20
X=45
Y=0
FontSize=14
SolidColor=200,200,200,255
FontColor=255,255,255
AntiAlias=1
ClipString=1
InlineSetting=CharacterSpacing | 2 | 2
DefaultValue=#MT#
Command1=[!WriteKeyValue "Variables" "MT" "$UserInput$"][!Refresh]
DynamicVariables=1

[MT_Record]
Meter=String
W=40
H=20
X=45
Y=0
FontSize=14
FontFace=#FFT#
FontColor=#CT#
SolidColor=200,200,200,1
DynamicVariables=1
Text=#MT#mo
LeftMouseUpAction=[!CommandMeasure "MT_Write" "ExecuteBatch 1"][!RainmeterRedraw]
Hidden=0

[DY_Write]
Measure=Plugin
Plugin=InputText
FontFace=#FFT#
W=30
H=20
X=90
Y=0
FontSize=14
SolidColor=200,200,200,255
FontColor=255,255,255
AntiAlias=1
ClipString=1
InlineSetting=CharacterSpacing | 2 | 2
DefaultValue=#DY#
Command1=[!WriteKeyValue "Variables" "DY" "$UserInput$"][!Refresh]
DynamicVariables=1

[DY_Record]
Meter=String
W=40
H=20
X=90
Y=0
FontSize=14
FontFace=#FFT#
FontColor=#CT#
SolidColor=200,200,200,1
DynamicVariables=1
Text=#DY#dy
LeftMouseUpAction=[!CommandMeasure "DY_Write" "ExecuteBatch 1"][!RainmeterRedraw]
Hidden=0


[DragNDropParent]
Measure=Plugin
Plugin=Drag&Drop

[DragNDropChild1]
Measure=Plugin
Plugin=Drag&Drop
Parent=DragNDropParent
Bounds=Box1
Action=Path
OnOverAction=[!SetOption DragNDropChild1 OnDropAction """[!WriteKeyValue "Variables" "Image1" "$File$" "#@#log\#YR##MT##DY#.inc""][!Update]"""][!Update]
OnLeaveAction=[!SetOption DragNDropChild1 OnDropAction ""][!Update]


[Receive1]
Measure=Plugin
Plugin=Drag&Drop
Parent=DragNDropParent
Bounds=Box1
Action=Copy
FilePath=Save\#YR##MT##DY#

[MeasureFileName1]
Measure=String
RegExpSubstitute=1
String=#Image1#
Substitute=".*\\(.*)":"\1"

[Box1]
Meter=Image
ImageName=#name1#
DynamicVariables=1
PreserveAspectRatio=2
X=0
Y=30
W=150
H=150
MouseOverAction=[!SetOption "Box1" "ImageTint" "150,150,150,255"][!Update]
MouseLeaveAction=[!SetOption "Box1" "ImageTint" "255,255,255,255"][!Update]
LeftMouseUpAction=[#SKINSPATH#Todo\Save\#YR##MT##DY#]
RightMouseUpAction=[!refresh][!WriteKeyValue "Variables" "name1" "C:\Users\USER\Documents\Rainmeter\Skins\Todo\Save\#YR##MT##DY#\[MeasureFileName1]" "#@#log\#YR##MT##DY#.inc""]
@Resources\log\200731.inc

Code: Select all

[Variables]
Image1=C:\Users\USER\Documents\Rainmeter\Skins\Todo\Images\BoxB3.png
Name1=C:\Users\USER\Documents\Rainmeter\Skins\Todo\Images\BoxB3.png
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: How to extract file names

Post by jsmorley »

Good deal!