SenzoD
(Senzo Dlomo)
April 7, 2020, 4:21pm
1
Hi all,
i have the string below, its a path to an image and i need to get the name of the image
*C:\Users\SenzoD\Desktop\Automation-Project101\SampleImages\IM-0019-0001.jpeg’
the word i need is IM-0019-0001 and please note this word changes all the time but everything else stays the same
Thanks in advanced
msan
(Michel SAN)
April 7, 2020, 4:27pm
2
Here is a pattern:
[^\\]+$
for this kind of search I’d tend use Path.GetFileName
1 Like
SenzoD
(Senzo Dlomo)
April 7, 2020, 4:32pm
3
Hi @msam , thanks for your help, i also need to exclude .jpeg, please help me with that also
msan
(Michel SAN)
April 7, 2020, 4:43pm
4
(?<filename>[^\\]+)(?<extension>\.\w+)$
You can then use on the resulting match (MyMatch):
MyMatch.Groups("filename").ToString
or Path.GetFileNameWithoutExtension
1 Like
hey buddy @SenzoD
i hope your doing this in for each loop you can do this
use assign value like this strVar = path.GetFileName(item).split("."c)(0)
2 Likes
GBK
(GBK)
April 8, 2020, 8:59am
6
@SenzoD -
Insted of writting regex logic to get the file name -
Crate a variable ex fileName
fileName = Path.GetFileNameWithoutExtension(“C:\Users\SenzoD\Desktop\Automation-Project101\SampleImages\IM-0019-0001.jpeg”)
2 Likes