Jump to content
Sign in to follow this  

StringSplit count from right side

Recommended Posts


If i have a file path like this:


I need in my script to extract "folder1" name to get album name...

I did try that with SplitString but it counts arrays from left to right

If it could read it from right to left I would ask for $array[2] and problem solved

What I did is:

;here is path

;here i set "\" as delimiter
$split = StringSplit($path,"\")

;this number shows how many strings i got by spliting

I did try to substract one number from "$array[0]" to get number of arrays substracted by one to get last folder name.

But I dont know how to do that...

How can I always get name of folder1 if there are different folder numbers till mp3 file?


d:\folder6\folder5\folder4\folder3\folder2\folder1\musicfile.mp3 (array[7])

d:\folder5\folder4\folder3\folder2\folder1\musicfile.mp3 (array[6])

d:\folder3\folder2\folder1\musicfile.mp3 (array[4])

d:\folder1\musicfile.mp3 (array[2])

d:\folder4\folder3\folder2\folder1\musicfile.mp3 (array[5])

I always need folder1 but autoit read it like this:



Any help?

BTW I am using this: _Winamp_GetCurrentTrackFilePath() to get path name... Is there name just to get folder name in that UDF maybe? It will be much better and easier...

Thanks in advance!

Share this post

Link to post
Share on other sites

$sPath = "d:\folder6\folder5\folder4\folder3\folder2\folder1\musicfile.mp3"
$sFolder = StringRegExpReplace($sPath, "(?m:^|\n).*\\(.+?)\\.+$", "$1")

If you feel more comfortable with StringSplit try this

$sPath = "d:\folder6\folder5\folder4\folder3\folder2\folder1\musicfile.mp3"
$aPath = StringSplit($sPath, "\")
If NOT @Error Then
    $sFolder = $aPath[Ubound($aPath)-2]


Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver: - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post

Link to post
Share on other sites

Thank You very much... Second example works... First one I didnt even try but i will tomorrow... Its 5am here and this bothered me much.. couldn't sleep! Thanks again for simple example!

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this