Skip to main content

Topic: $directory() should be able to go forwards too (Read 4253 times) previous topic - next topic

0 Members and 1 Guest are viewing this topic.
  • yatahaze
  • [*][*]
$directory() should be able to go forwards too
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.
  • Last Edit: 02 April, 2006, 06:44:14 PM by yatahaze

  • Cosmo
  • [*][*][*][*][*]
$directory() should be able to go forwards too
Reply #1
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.
  • Last Edit: 02 April, 2006, 08:21:11 PM by Cosmo

  • yatahaze
  • [*][*]
$directory() should be able to go forwards too
Reply #2
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.
  • Last Edit: 04 April, 2006, 10:51:19 PM by yatahaze

  • c0utta
  • [*][*]
$directory() should be able to go forwards too
Reply #3
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

  • Cosmo
  • [*][*][*][*][*]
$directory() should be able to go forwards too
Reply #4
I'm sorry... I completely missed the point - that you wanted to go N levels starting at the beginning of the path.

  • yatahaze
  • [*][*]
$directory() should be able to go forwards too
Reply #5
Yes, that summed it up. Now, is this somewhere where anyone is actually gonna see it and do something with it? heh

  • Birk
  • [*][*]
$directory() should be able to go forwards too
Reply #6
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...

$directory() should be able to go forwards too
Reply #7
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?

  • yatahaze
  • [*][*]
$directory() should be able to go forwards too
Reply #8
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!!
  • Last Edit: 04 April, 2006, 10:58:16 PM by yatahaze

  • Frank Bicking
  • [*][*][*][*][*]
  • Global Moderator
$directory() should be able to go forwards too
Reply #9
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.
  • Last Edit: 08 July, 2006, 07:59:32 PM by Frank_Bicking