Jump to content
Sign in to follow this  
Fr33b0w

StringSplit count from right side

Recommended Posts

Fr33b0w

If i have a file path like this:

d:\folder6\folder5\folder4\folder3\folder2\folder1\musicfile.mp3

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
$path=d:\folder6\folder5\folder4\folder3\folder2\folder1\musicfile.mp3

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

;this number shows how many strings i got by spliting
$number=$split[0]

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?

Example:

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:

d:\folder1\folder2\folder3\folder4\folder5\folder6\musicfile.mp3

d:(array[1])\folder1(array[2])\folder2(array[3])\folder3(array[4])\folder4(array[5])\folder5(array[6])\folder6(array[7])\musicfile.mp3(array[8])

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
GEOSoft

$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]
EndIf

George

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:3.0.1.13) - 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
Fr33b0w

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  

×