-1

I have been learning and using Extendscript with After Effects CS6 (normally use maxscript and python) to create a dockable UI for After Effects. I have managed to do this, but need to restructure the code to search within folders in a root folder to grab the .jsx files that form the nodes on the treeview I have created.

currently, all the .jsx files are in one root folder, but due to a restructuring of the folder system, we now have a folder that houses each script

I need to be able to return/collect the names of folders within the root folder into an array that I can loop over in the later part of the script.

So far I have code that will return the path to the folders inside the root folder, but this is not what I need and I do not want to have to split the strings into constituent parts just to get the last part of the path.

The root folder in the image below is "c:\AFX\theRoot\" with folders inside named script1, script2, script3 script4

I was going to post an image of the folder structure, but I am not allowed due to a requirement to have a specific rating.

EMJAY
  • 5
  • 7
  • You have the subfolders but you "do not want to have to split the strings"? Why not? It's a straightforward operation (and it won't physically hurt the strings). – Jongware Oct 26 '14 at 09:47
  • For an experienced Java scripter, that may be the case, but as mentioned, I do not use Javascript and extendscript on a daily basis. Instead of pointing out how simple it is, perhaps post a working example so I can learn from it as what you put so far is of no help. I do not want to appear ungrateful, but so far, responses have not provided any help to assist moving forward. – EMJAY Nov 05 '14 at 10:46
  • Sure. But first, you should simply show what you have (or only a snippet if the code is long and the problem is localized) and point out where you run into problems. Second, you describe the issue *as if* you know how to split off the path but "do not want to have to". Hence my question: why don't you want to do so? – Jongware Nov 05 '14 at 10:53
  • var ScriptsFolder = "Z:\\ddtest\\Malc\\all_MJA_Folders\\TestingFolders\\afterEffextsTests\\"; // ROOT folder location var aFolder = new Folder("Z:\\ddtest\\Malc\\all_MJA_Folders\\TestingFolders\\afterEffextsTests") var foldername = aFolder.name; print(foldername); – EMJAY Nov 05 '14 at 12:42
  • {//Start var AFXScriptsFolder = "Z:\\ddtest\\Malc\\all_MJA_Folders\\TestingFolders\\afterEffextsTests\\" var AFXFolderList = []; subfolders AFXFolderList = collectSubFolders(Folder(AFXScriptsFolder)); function collectSubFolders(theFolder) { if (AFXScriptsFolder != null ) { var foundFolders = theFolder.getFiles(); for(each in foundFolders) { print(foundFolders[each].toString()); } } } }//END – EMJAY Nov 05 '14 at 12:53
  • /z/ddtest/Malc/all_MJA_Folders/TestingFolders/afterEffextsTests/SubFolder_01 /z/ddtest/Malc/all_MJA_Folders/TestingFolders/afterEffextsTests/SubFolder_02 /z/ddtest/Malc/all_MJA_Folders/TestingFolders/afterEffextsTests/SubFolder_03 /z/ddtest/Malc/all_MJA_Folders/TestingFolders/afterEffextsTests/findThisSucker.txt The above is everything in the root folder, but I need just folders and the ability to use the folder names in a later search that I can manipulate to my own needs. – EMJAY Nov 05 '14 at 12:55
  • Thanks very much. After rereading my first post, it does come across as if I knew more than I did, so apologies for any misconception made surrounding the inaccuracy of the initial question. – EMJAY Nov 05 '14 at 12:57

1 Answers1

1

If you already have strings. Operating on them is probably the easiest way to get the folder name. Instead of splitting you could also use a regex like this:

var name = yourString.match(/([^\/]*)\/*$/)[1]

Credit for the regex goes to this thread

If you have some reason not to do it this way, there is the folder object in ExtendScript. You can create a new folder from a string like this:

var folder = new Folder("/your/folders/name");

And get the name like this:

var name = folder.name

Hope this helps.

Community
  • 1
  • 1
Jonas
  • 956
  • 6
  • 12
  • Thank you for the help and information, it is very much appreciated . When you see the code, it always seems so logical. I will post my example script after this is implemented. I already have a function that looks for .jsx files and collates them from a single folder location, I was just wondering how I would go through a set of folders in a specified root folder to get the script name from within the individual folders and ignoring any other file types. I know the logic, just not the syntax currently, but each day is chipping away at it. – EMJAY Oct 29 '14 at 14:29
  • As I am the creator of the question, I am unsure why my replies to my own question were deleted. I really need some help with the issue, so hope that this post will be allowed to stay so that I can get some input. I need to be able to go to a specified root folder that already exists and does not need creating. Collate only folders inside the root folder into an array Use a for loop to iterate through each folder and find jsx files and append the results into an array. – EMJAY Nov 05 '14 at 10:34
  • I do not need to create new folders. I need to collate existing folders in an existing root folder and store the folder names found in that root folder into an array so that I can iterate over them in a function that will dynamically create a treeview using icons found in the sub folders etc. – EMJAY Nov 05 '14 at 11:19
  • `new Folder("/your/folders/name/")` doesn't create a folder in the file system. It gives you an object representation of the folder you give it as an argument. On this object you can use methods, for example to get all the files/subfolders (`getFiles()`). See the documentation for more in-depth info: http://wiki.ecmascript.org/lib/exe/fetch.php?id=proposals%3Afilesystem&cache=cache&media=proposals:adobefilefolder.pdf – Jonas Nov 07 '14 at 14:10
  • Hi Jonas, thank you for the replies and the information, I will be sure to store these pointers. I did manage on friday to get what I need and now have a script that builds the ui treeview with items found in the root folder. Also managed to get icons for each item as well. I am now rewriting the event functinality to read in an execute a script based on tree item selection. Once I realised that extendscript/javascript is a lot like MEL for Maya, things started to fall into place. – EMJAY Nov 10 '14 at 09:08
  • Ok, so the ui is working but I have hit a snag. I am collecting a path from the system and it has single backslashe in the path and I need to replace them with a double backslash. I have tried .replace, regex, and a myriad of other ways, but I cannot get it to replace the character. The path I am trying to resolve is this:"Z:\assets\scripts\aftereffects\burrowsAFXScriptLister\scripts\Folder_Setup\Folder_Setup.jsx" – EMJAY Nov 11 '14 at 14:42
  • Well, with only one reply and no help from anyone else, I have written the dynamic ui and it is working. Just goes to show that you can only rely on yourself. – EMJAY Nov 13 '14 at 15:58
  • @EMJAY: please do not ask additional questions or show your progress as *answers*; also, please do not put important information such as the code you wrote so far in *comments*. For both, you can easily edit your original question. – Jongware Nov 22 '14 at 01:51
  • @Jongware: Thanks for reminding me about posts I have already been contacted about. If only people would be as responsive with information surrounding what I was looking for help with when posting then I would not have to answer my own questions or put comments that I was hoping others would see. I cant add images, cant post unless I have a certain reputation, can only post under spurious rules, so no need to worry, I will not be coming back as I have had nothing replied to that could remotely be called help. – EMJAY Nov 24 '14 at 11:13
  • @Jongware: As a learner, I was hoping that this site would be a resource, but in reality, its just been people moaning about me asking questions. Is that not what this site is supposed to be for? How can I edit my own questions when they keep getting removed? – EMJAY Nov 24 '14 at 11:13
  • @EMJAY: please read my earlier comments (also see the *unreadable* code in the comments under your post). I'm sorry to read you are disappointed with SO so far -- perhaps you were expecting too much? **But Comments are not the proper place to communicate this.** Perhaps you should open a discussion on [Meta Stack Overflow](http://meta.stackoverflow.com/). – Jongware Nov 24 '14 at 11:21
  • How can I be expecting too much when all I got was an incorrect response to a question I laid out in plain English? I was not expecting the code I needed to be written for me, but after waiting for a period of time with no articulate response to this, and other questions I have posed to the experts who use this site, I do not feel that I was asking for a lot. Which posts of yours are you talking about? The one where you unhelpfully told me it was simple and then offered no insight or the other post where you start having a pop about putting responses? Neither of which did anything to help me – EMJAY Nov 24 '14 at 13:47