$directory() should be able to go forwards too |
This is NOT a tech support forum.
Tech support questions go to foobar2000 Tech Support forum instead.
See also: Hydrogenaudio Terms of Service.
![]() ![]() |
$directory() should be able to go forwards too |
Apr 2 2006, 23:24
Post
#1
|
|
![]() Group: Members Posts: 64 Joined: 13-March 05 Member No.: 20590 |
I'm not sure where the place is that the developer reads suggestions and stuff, so I'll post this here. I use $directory(%_path%,1) to get the album folder, but there is a directory that is 1 or somtimes 2 directories back from that which I want to get but can't using that code.
My directory layout: F:\Albums\New\Date\AlbumFolder\file.mp3 F:\Albums\New\Date\AlbumFolder\file.mp3 F:\Albums\New\Date\Genre\AlbumFolder\file.mp3 F:\Albums\New\Date\Genre\AlbumFolder\file.mp3 F:\Albums\SomeSortedFolder\AlbumFolder\file.mp3 F:\Albums\SomeSortedFolder\AlbumFolder\file.mp3 Right now I can easily grab anything from the back of the path (for example the AlbumFolder) easily, but I'd like to be able to grab as many folders from the FRONT that I want (the New/SomeSortedFolder). I hope this makes sense. To have this feature would make me reaaaaally happy For the past year or so I guess I've been using this to get the job done, but it doesnt work that great: $trim($substr(%_path%,$add($strchr(%_path%,.),2),$sub($strrchr($substr(%_path%,0,45),\),1))) I'm open for any other suggestions on how to get this done too. This post has been edited by yatahaze: Apr 2 2006, 23:44 |
|
|
|
Apr 3 2006, 01:12
Post
#2
|
|
![]() Group: Members Posts: 913 Joined: 10-January 05 Member No.: 18979 |
Ever seen "titleformat_help.html" in foobar's directory, or the online Title Formatting documentation ?
QUOTE $directory(X,N) Extracts directory name from file path X, goes up by N directory levels. example path .... "X:\Music\Genre\Artist\Album\file.mp3" $directory(%path%,1) returns: "Album" ...(%directory% also returns: "Album") $directory(%path%,2) returns: "Artist" $directory(%path%,3) returns: "Genre" etc. This post has been edited by Cosmo: Apr 3 2006, 01:21 |
|
|
|
Apr 3 2006, 01:23
Post
#3
|
|
![]() Group: Members Posts: 64 Joined: 13-March 05 Member No.: 20590 |
Yeah, the number decided how many steps back to go from the end of the file path. I would like to have the option to do the exact same thing, but go from the start of the file path.
My example: X:/Music/Genre/Artist/Album/file.mp3 $directory(%_path%,1) returns "Album" $dirfromstart(%_path%,1) returns "Music" Using that example, $dirfromstart(%_path%,1) would always return "Music" regardless of how many subfolders I create inside it. This post has been edited by yatahaze: Apr 5 2006, 03:51 |
|
|
|
Apr 3 2006, 02:09
Post
#4
|
|
|
Group: Members Posts: 50 Joined: 28-May 05 Member No.: 22351 |
yatahaze,
I agree totally - I have also used TAGZ to try and extract directories from the start of the path. I always thought that $directory() was the wrong way round - it should use negatives to move up the tree and positives to move down. example path .... "X:\Music\Genre\Artist\Album\file.mp3" $directory(%path%,-1) returns: "Album" $directory(%path%,-2) returns: "Artist" $directory(%path%,-3) returns: "Genre" etc and $directory(%path%,1) returns: "Music" ...(%directory% also returns: "Album") $directory(%path%,2) returns: "Genre" $directory(%path%,3) returns: "Artist" etc Maybe $directory() could do the reverse of this (so as not to wreck existing scripts) use the negative numbers to indicate that you want to come from the start? Cheers, c0utta |
|
|
|
Apr 3 2006, 02:37
Post
#5
|
|
![]() Group: Members Posts: 913 Joined: 10-January 05 Member No.: 18979 |
I'm sorry... I completely missed the point - that you wanted to go N levels starting at the beginning of the path.
|
|
|
|
Apr 3 2006, 04:36
Post
#6
|
|
![]() Group: Members Posts: 64 Joined: 13-March 05 Member No.: 20590 |
Yes, that summed it up. Now, is this somewhere where anyone is actually gonna see it and do something with it? heh
|
|
|
|
Apr 3 2006, 11:17
Post
#7
|
|
|
Group: Members Posts: 98 Joined: 3-January 05 Member No.: 18814 |
You can use this:
CODE $puts(dir,%path%) $puts(directory1,$left($put(dir,$substr($get(dir),$add($strstr($get(dir),\),1),999)),$sub($strstr($get(dir),\),1))) $puts(directory2,$left($put(dir,$substr($get(dir),$add($strstr($get(dir),\),1),999)),$sub($strstr($get(dir),\),1))) $puts(directory3,$left($put(dir,$substr($get(dir),$add($strstr($get(dir),\),1),999)),$sub($strstr($get(dir),\),1))) $puts(directory4,$left($put(dir,$substr($get(dir),$add($strstr($get(dir),\),1),999)),$sub($strstr($get(dir),\),1))) $puts(directory5,$left($put(dir,$substr($get(dir),$add($strstr($get(dir),\),1),999)),$sub($strstr($get(dir),\),1))) with "F:\Albums\SomeSortedFolder\AlbumFolder\file.mp3" $get(directory1) returns Albums $get(directory2) returns SomeSortedFolder $get(directory3) returns AlbumFolder $get(directory4) returns file.mp3 $get(directory5) returns file.mp3, too. This is the only problem... |
|
|
|
Apr 3 2006, 11:23
Post
#8
|
|
|
Group: Members Posts: 21 Joined: 6-March 05 Member No.: 20404 |
QUOTE (Birk @ Apr 3 2006, 06:17 PM) You can use this: CODE $puts(dir,%path%) $puts(directory1,$left($put(dir,$substr($get(dir),$add($strstr($get(dir),\),1),999)),$sub($strstr($get(dir),\),1))) $puts(directory2,$left($put(dir,$substr($get(dir),$add($strstr($get(dir),\),1),999)),$sub($strstr($get(dir),\),1))) $puts(directory3,$left($put(dir,$substr($get(dir),$add($strstr($get(dir),\),1),999)),$sub($strstr($get(dir),\),1))) $puts(directory4,$left($put(dir,$substr($get(dir),$add($strstr($get(dir),\),1),999)),$sub($strstr($get(dir),\),1))) $puts(directory5,$left($put(dir,$substr($get(dir),$add($strstr($get(dir),\),1),999)),$sub($strstr($get(dir),\),1))) with "F:\Albums\SomeSortedFolder\AlbumFolder\file.mp3" $get(directory1) returns Albums $get(directory2) returns SomeSortedFolder $get(directory3) returns AlbumFolder $get(directory4) returns file.mp3 $get(directory5) returns file.mp3, too. This is the only problem... But this is too complex to use. Is there a funtion do the same thing? |
|
|
|
Apr 5 2006, 03:50
Post
#9
|
|
![]() Group: Members Posts: 64 Joined: 13-March 05 Member No.: 20590 |
How do I use this? I added that code to the columns ui globals section, then I made a column and put $get(directory3) in it, but nothing shows. Am I doing that right?
Edit: Nevermind, I chucked all the code with $get(directory3) at the end into a column and it works PERFECTLY! Exactly what I needed.. thanks!! This post has been edited by yatahaze: Apr 5 2006, 03:58 |
|
|
|
Jul 9 2006, 00:05
Post
#10
|
|
![]() Group: Super Moderator Posts: 1813 Joined: 24-July 02 Member No.: 2776 |
Much shorter solution:
CODE $directory(%path%,$sub($sub($len(%path%),$len($replace(%path%,\,))),1)) The number at the end defines how many directory levels it should go down from the root. This post has been edited by Frank_Bicking: Jul 9 2006, 00:59 -------------------- foobar2000.audiohq.de
|
|
|
|
![]() ![]() |
|
Lo-Fi Version | Time is now: 24th May 2013 - 07:52 |