[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [sc-users] Folder Depth



hi,
fun!
here's my variant.  basically the same as yours but using a few tricks to make it more compact: withTrailingSlash, pathSeparator.

(
var initpath= PathName("~/Documents/soundfiles");
var depth= 0; // set how deep you want to go
var initPathDepthCount= initpath.fullPath.withTrailingSlash.split(thisProcess.platform.pathSeparator).size;
~acceptedItems= Set.new();
~rejectedItems= Set.new();
initpath.deepFiles.do{|item|
if(item.fullPath.split(thisProcess.platform.pathSeparator).size-initPathDepthCount<=depth, {
~acceptedItems.add(item);
"accepted\n\t -> %\n".format(item.fileName).postln;
}, {
~rejectedItems.add(item);
"rejected\n\t -> %\n".format(item.fileName).postln;
});
};
"number of accepted files %".format(~acceptedItems.size).postln;
"number of rejected files %".format(~rejectedItems.size).postln;
~acceptedItems.clear;
~rejectedItems.clear;
"".postln;
)

_f

10 dec. 2019 kl. 22:00 skrev adam@xxxxxxxxxx:

commercials aside.

Really interested in knowing of other ways of doing this. possibly more concise?

here is a rewritten or standalon-ifizied example from the audio file loader class I mentioned in the previous post

________________________


(
var initpath = "~/Desktop";
var initPathDepthCount = 0;
var depth = 0; // set how deep you want to go

~acceptedItems = Set.new();
~rejectedItems = Set.new();

// protection against setting an initpath ending with / or // etc
while({initpath.endsWith("/")}, {"removed /".postln; initpath = initpath[..initpath.size-2]});
// if init path ends with $/ it will break the depth control

// count depth in initpath
PathName(initpath).pathOnly.do{ | char |
    if (char == $/, {initPathDepthCount = initPathDepthCount + 1;})
};

// add this to depth
depth = depth + initPathDepthCount;

// do for all files and check depth guard
PathName(initpath).filesDo{ | item |
   
    var depthCounter = 0;
    var depthGuard;
   
    item.pathOnly.do{ | char |
        // linux      /    windows    \\
        if (char == ($/) || (char == ($\\)), {
            if (depthCounter <= depth, {
                depthGuard = false;
                depthCounter = depthCounter+1;
            }, {
                depthGuard = true;
            });
        })
    };
   
    if (depthGuard == false, {
        ~acceptedItems.add(item);
    }, {
        ~rejectedItems.add(item)
    });
   
};

~acceptedItems.do{|item|
    "accepted\n\t -> %\n".format(item.fileName).postln;
};

~rejectedItems.do{|item|
    "rejected\n\t -> %\n".format(item.fileName).postln;
};

"number of accepted files %".format(~acceptedItems.size).postln;
"number of rejected files %".format(~rejectedItems.size).postln;

~acceptedItems.clear;
~rejectedItems.clear;
"".postln;
)

___________________________________



On 09/12/2019 18:18, adam@xxxxxxxxxx wrote:
A possible not so optimized or poorly written 😁 depth control is implemented in my Convenience class.

Drag and drop any folder and Convenience.crawl will go into this path and load all audiofiles in its way. Depth control (from folder into folders into folders etc) is set by an integer.

It works really well, but better ways or other ways of doing this is highly appreciated.

Maybe implemented in PathName as the OP hints at?

na~
Den 9. dec. 2019, fra 14.54, f@xxxxxxxxxxxxxxxxxxx skrev:
the .filesDo method implements recursion (check the sourcecode).
will that do or do you need to stop at a certain depth?

(
var myPath;
myPath = PathName.new("~/quarks".standardizePath);
myPath.filesDo{|afile| afile.postln};
)

_f

9 dec. 2019 kl. 14:37 skrev jables.deutsch@xxxxxxxxx:

Hey SC Users,

Is there a typical method or approach for searching the folders within folders, within a pathMatch convention? 








  #|
  |#

-- 
Venlig hilsen,
Niklas Adam

adam@xxxxxxxxxx
niklasadam.oddodd.org
Leveringsadresse: Ullevålsveien 111 B, 0359 Oslo

niklas@xxxxxxxxxxxxxxxxxx
verdensteatret.com
Besøks-/leveringsadresse: Verkseier Furulunds vei 22, 0668 Oslo
Fakturaadresse: Verdensteatret, Marselisgt 27, 0551 Oslo
Orgnr: 975 600 874 


  #|
  |#