HydrogenAudio

Hosted Forums => foobar2000 => General - (fb2k) => Topic started by: yatahaze on 2006-04-02 23:24:34

Title: $directory() should be able to go forwards too
Post by: yatahaze on 2006-04-02 23:24:34
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.
Title: $directory() should be able to go forwards too
Post by: Cosmo on 2006-04-03 01:12:37
Ever seen "titleformat_help.html" in foobar's directory, or the online Title Formatting documentation (http://wiki.hydrogenaudio.org/index.php?title=Foobar2000:Titleformat_Reference#.24directory.28x.2Cn.29) ?

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.
Title: $directory() should be able to go forwards too
Post by: yatahaze on 2006-04-03 01:23:55
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.
Title: $directory() should be able to go forwards too
Post by: c0utta on 2006-04-03 02:09:39
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
Title: $directory() should be able to go forwards too
Post by: Cosmo on 2006-04-03 02:37:53
I'm sorry... I completely missed the point - that you wanted to go N levels starting at the beginning of the path.
Title: $directory() should be able to go forwards too
Post by: yatahaze on 2006-04-03 04:36:10
Yes, that summed it up. Now, is this somewhere where anyone is actually gonna see it and do something with it? heh
Title: $directory() should be able to go forwards too
Post by: Birk on 2006-04-03 11:17:20
You can use this:
Code: [Select]
$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...
Title: $directory() should be able to go forwards too
Post by: wangyi6854 on 2006-04-03 11:23:15
Quote
You can use this:
Code: [Select]
$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...
[a href="index.php?act=findpost&pid=378526"][{POST_SNAPBACK}][/a]


But this is too complex to use. Is there a funtion do the same thing?
Title: $directory() should be able to go forwards too
Post by: yatahaze on 2006-04-05 03:50:40
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!!
Title: $directory() should be able to go forwards too
Post by: Frank Bicking on 2006-07-09 00:05:38
Much shorter solution:

Code: [Select]
$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.