Looping Through Subfolders

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Looping Through Subfolders

Martin Marris

ManuScript lets you loop through folders with a for each loop, searching for particular types of files. But what if you want to loop through the subfolder objects that are in the main folder (and return only those objects)? By default, Sibelius loops through the top-level folder recursively (i.e. it will return the file objects from the sub-folders). But what I’m trying to do is identify the sub-folders per se, and process them individually with branching that depends on their names or their content type.

 

for each TXT file in folder

 

works fine as a way to find text files, but there doesn’t seem to be a way to do something like this to find folders:

 

for each FOL subfolder in folder

 

I tried this:

 

for each obj in folder

     {

     trace (obj.Type);

     }

 

But this doesn’t give any results at all, not even for the non-folder objects inside the folder. It seems that this type of loop only works if you supply a filter/extension type (SIB, or TXT, or whatever).

 

(I can use other techniques to identify sub-folders, basically by parsing a file object’s name string and looking for “\\” delimiters after the name of the top-level folder; and I have done such things in the past. I was just hoping there might be a more direct way to identify subfolders.)

 

Martin

 


_______________________________________________
Plugin-dev mailing list
[hidden email]
http://avid-listsrv1.avid.com/mailman/listinfo/plugin-dev
Reply | Threaded
Open this post in threaded view
|

Re: Looping Through Subfolders

Bob Zawalich

No there is no easier way I know of.  There is no way to process folders, just files. So if I need to  figure out a specific folder I  deconstruct the path names looking for Sibelius.PathSeparator.

 

Enumerating a folder  gives Sibelius Files, not score objects, according to the doc. I have always enumerated for a specific file type, so I do not know from experience if that actually works to get Sib files. I suspect it should. Obj.Type only works for Bar Objects.

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Martin Marris
Sent: Saturday, February 27, 2016 1:18 PM
To: A mailing list for Sibelius plug-in developers
Subject: [Plugin-dev] Looping Through Subfolders

 

ManuScript lets you loop through folders with a for each loop, searching for particular types of files. But what if you want to loop through the subfolder objects that are in the main folder (and return only those objects)? By default, Sibelius loops through the top-level folder recursively (i.e. it will return the file objects from the sub-folders). But what I’m trying to do is identify the sub-folders per se, and process them individually with branching that depends on their names or their content type.

 

for each TXT file in folder

 

works fine as a way to find text files, but there doesn’t seem to be a way to do something like this to find folders:

 

for each FOL subfolder in folder

 

I tried this:

 

for each obj in folder

     {

     trace (obj.Type);

     }

 

But this doesn’t give any results at all, not even for the non-folder objects inside the folder. It seems that this type of loop only works if you supply a filter/extension type (SIB, or TXT, or whatever).

 

(I can use other techniques to identify sub-folders, basically by parsing a file object’s name string and looking for “\\” delimiters after the name of the top-level folder; and I have done such things in the past. I was just hoping there might be a more direct way to identify subfolders.)

 

Martin

 


_______________________________________________
Plugin-dev mailing list
[hidden email]
http://avid-listsrv1.avid.com/mailman/listinfo/plugin-dev
Reply | Threaded
Open this post in threaded view
|

Re: Looping Through Subfolders

Martin Marris
Hi Bob,

That's what I thought, but thanks for confirming it. I will go back to my
old method of deconstructing the path names.

What I am trying to do is apply a different action to each sub-folder,
depending on its name.

>>Obj.Type only works for Bar Objects.<<

If you do a "for each TXT file in folder .. Trace(TXT.Type)" it will return
"File" as the Type. This is not terribly useful however, since there is no
way to trace the non-file objects in the folder (i.e. the subfolders).

The Sibelius "Folder" object does have a Type variable, namely, "Folder" but
I'm not clear how you would use it.

Martin


_______________________________________________
Plugin-dev mailing list
[hidden email]
http://avid-listsrv1.avid.com/mailman/listinfo/plugin-dev
Reply | Threaded
Open this post in threaded view
|

Re: Looping Through Subfolders

Bob Zawalich
Yeah, I often have to deal with shipping and user plugins differently, and
so I do the same sort of thing.

I had not noticed that File and Folder objects have a type.  At least if you
ask for Type on such an object Sib will not crash!

Enumerating a folder gives you Sib files if you do not specify a type, and
files of the types you specify otherwise, so it is always files. I have
sometimes wished for the ability to get file handles for files of arbitrary
types, but that never happened and I don't expect it ever will.

Cheers

Bob


-----Original Message-----
From: Martin Marris [mailto:[hidden email]]
Sent: Saturday, February 27, 2016 1:54 PM
To: [hidden email]; 'A mailing list for Sibelius plug-in developers'
Subject: RE: [Plugin-dev] Looping Through Subfolders

Hi Bob,

That's what I thought, but thanks for confirming it. I will go back to my
old method of deconstructing the path names.

What I am trying to do is apply a different action to each sub-folder,
depending on its name.

>>Obj.Type only works for Bar Objects.<<

If you do a "for each TXT file in folder .. Trace(TXT.Type)" it will return
"File" as the Type. This is not terribly useful however, since there is no
way to trace the non-file objects in the folder (i.e. the subfolders).

The Sibelius "Folder" object does have a Type variable, namely, "Folder" but
I'm not clear how you would use it.

Martin



_______________________________________________
Plugin-dev mailing list
[hidden email]
http://avid-listsrv1.avid.com/mailman/listinfo/plugin-dev