extendscript, get folder name - get

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.

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.

Related

I want to copy files at the bottom of the folder hierarchy and put them in one folder

In Azure Synapse Analytics, I want to copy files at the bottom of the folder hierarchy and put them in one folder.
The files you want to copy are located in their respective folders.
(There are 21 files in total.)
enter image description here
I tried it using ability to flatten the hierarchy of "Copy" activity.
However, as you can see in the attached image, the file name is created on the Synapse side.
enter image description here
I tried to get the name of the bottom-level file with the "Get Metadata" activity, but I could not use wildcards in the file path.
I considered creating and running 21 pipelines that would copy each file, but since the files are updated daily in Blob, it would be impractical to run the pipeline manually every day using 21 folder paths.
Does anyone know of any smart way to do this?
Any help would be appreciated.
Using flatten hierarchy does not preserve existing file name, new file name will be generated. Wildcard paths are not accepted by Get metadata activity. Hence one option is to use Get Metadata with ForEach to achieve the requirement.
The following are the images of folder structure that I used for this demonstration.
I created a Get Metadata activity first. I am retrieving the folder names (21 folders like '20220701122731.zip') inside Intage Sample folder using field list as child items.
Now I used ForEach activity to loop through these folders names by giving items value as #activity('Get folders level1').output.childItems.
Inside ForEach I have 3 activities. First is another Get Metadata activity to get the subfolder names (to get one folder inside '20220701122731.zip', that is '20220701122731')
In this, while creating dataset, we passed the name of parent folder (folder_1 = '20220701122731.zip') to the dataset to use it in the path as
#{concat('unzipped/Intage Sample.zip/Intage Sample/',dataset().folder_1)}
This returns the names of subfolders (like '20220701122731') which are inside parent folder (like '20220701122731.zip' which have 1 subfolder each). I used set variable activity to assign the child items output to this variable using #activity('Get folder inner').output.childItems .
The final step is copy activity to move the required files to one single destination folder. Since there is only one sub-folder inside each of the 21 folders (only one sub-folder like '20220701122731' inside folder like '20220701122731.zip'), we can use the values achieved from above steps directly to complete the copy.
Along with the help of wildcard paths in this copy data activity, we can complete the copy. The wildcard directory path will be
#{concat('unzipped/Intage Sample.zip/Intage Sample/',item().name, '/', variables('test')[0].name)}
#item().name give parent folder name, in your case- '20220701122731.zip'
#variables('test')[0].name gives sub-folder name, in your case like '20220701122731'
For sink, I have created a dataset pointing to a folder inside my container called output_files. When triggered, the pipeline runs successfully.
The following are the contents of my output_files folder.

Transfer files under multiple folder from sftp to sharepoint document library using logic app

I have a scenario how to transfer files from sftp server to sharepoint document library
Example: files in sftp folder are /new/folder1/id1.csv /new/folder2/id2.csv like that every day the files will be uploaded to folders. how to transfer the same structure in sharepoint document library using logic apps..
The workflow for your folder structure would be as follows:
List files in your SFTP folder "/new".
Create a "For each" loop using the output of the list action as a parameter.
To make sure you don't treat files as folders (if you can have files in /new, e.g. /new/test.txt), add a condition: the IsFolder property of the loop item = true.
Inside the loop (and the condition result True) list files again, this time in the subfolder, using the Path property of the loop item.
Create a new "For each" loop using the output of this list action as a parameter.
Optionally, add a condition: the IsFolder property of the inner loop item = false.
Get content of the SFTP file, using the Id property of the inner loop item.
Create a file on SharePoint using the folder path, file name, and file content retrieved in the previous actions as parameters. If the folder doesn't exist in SharePoint library, it should be created automatically.
This is the most simple scenario, given the folder structure provided in your question. If the folder structure is more complex (subfolders can contain both files and subfolders, which in turn can contain other files and subfolders, and so on) then you'd need to use a recursive algorithm - first the Logic App would need to list files in a single SFTP folder (provided to the Logic App in the HTTP request body), then for each listed file (not subfolder) upload its content to SharePoint, and for each listed subfolder (not file) the Logic App would need to call itself passing the subfolder path in the HTTP request body - this way all subfolders would be processed recursively and all files in them would be transferred to SharePoint.
Please note that each such a workflow is run it would transfer all files - it wouldn't check what files are new, what files have been transferred in previous Logic App runs, etc. - that would be a completely different challenge.

Automatically create Subfolders on SharePoint Document Library

I have been trying to accomplish this for weeks now and end up hitting a wall.
I have a document library on SharePoint Online with the following (close enough) structure.
Clients
-> Schools
-->Client Name
--->Communications
--->Documentation
--->Projects
---->Project Name 1
---->Project Name 2
->Retail
-->Client Name
--->Communications
--->Documentation
--->Projects
---->Project Name 1
---->Project Name 2
... and so on.
Inside the "Projects" folder there is a set of folders as well.
Right now we have a Project template folder that we used to just copy/paste and rename when we had our file server, but now on SharePoint, the copy to process is way too many clicks to get it to that location.
What I am trying to accomplish is be able to create a new project folder and automatically create all the folders under it.
Appreciate the guidance on this.
I was able to figure this out.
My challenge was when creating the folder, it always wanted to create it inside the root of the document library and not the subfolder.
So I created 2 Content types for folders, one for clients and one for projects.
Used SharePoint Designer to create the workflow, but the trick here was to extract the URL from the current item, which is the folder being created, and remove the first x amount of characters from it which equals the SharePoint document library location. The remaining part of the string was the exact location where I wanted the subfolders to be created.
After that, I used that variable to create all other subfolders.

Accessing all the files from a folder

I'm trying to access all the files from a certain folder so that I can get their path and put it into an array. Once I get this array, I'd like to use it in a react file and display its contents on a page. I had a general idea of looping through the folder but couldn't find a solution to my problem. Is there a way to do this, directly or maybe through a third-party package?

Populate all the folders in a document library

I want to populate all the folders in document library to a drop down. I was thinking of using spquery for it but not sure how to retrieve all the folders with it.
You shoudl use the root folder of the lib and from that folder iterate through its Folders collection. Note that you need to set web.Lists.IncludeRootFolder to true to get access to the root folder.
But something I don't understand - folders have a tree-like structure, how do you intend to put them into a flat ddl?

Resources