cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
The Discovery Summit 2025 Call for Content is open! Submit an abstract today to present at our premier analytics conference.
See how to use to use Text Explorer to glean valuable information from text data at April 25 webinar.
Choose Language Hide Translation Bar
View Original Published Thread

List of folders

j_bonnouvrier
Level III

Hi,

I am looking forward a solution to get a list of folder in a given directory using JSL.

Thanks in advance!

Jerome

1 ACCEPTED SOLUTION

Accepted Solutions
ian_jmp
Level X


Re: List of folders

Something like this, perhaps?

 

 

Names Default To Here( 1 );
 
// Given a path to a folder, returns a list of all folders therein (not recursive!)
dirList =
Function({path}, {Default Local},
  // Get all files and folders in the specified folder
  fid = Files In Directory( path);
  // Remove all the files, just leaving the folders
  for(f=NItems(fid), f>=1, f--, if(IsFile(path||"/"||fid[f]), RemoveFrom(fid, f)));
  fid;
);
 
// Try out the function
path = "$DESKTOP";
Print(dirList(path));

 

View solution in original post

3 REPLIES 3
ian_jmp
Level X


Re: List of folders

Something like this, perhaps?

 

 

Names Default To Here( 1 );
 
// Given a path to a folder, returns a list of all folders therein (not recursive!)
dirList =
Function({path}, {Default Local},
  // Get all files and folders in the specified folder
  fid = Files In Directory( path);
  // Remove all the files, just leaving the folders
  for(f=NItems(fid), f>=1, f--, if(IsFile(path||"/"||fid[f]), RemoveFrom(fid, f)));
  fid;
);
 
// Try out the function
path = "$DESKTOP";
Print(dirList(path));

 

j_bonnouvrier
Level III


Re: List of folders

Indeed, something like this should help!

I will try to insert this in my script, but it should help me to go forward!

Thanks a lot Ian!

Jérôme

s_kris
Level I


Re: List of folders

It works really well.