cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
SC1
SC1
Level I

How do I open folder with unique identifier in name but variable ending?

I am trying to write a script to open a folder where the name of the folder contains halfway in the name a unique identifier.

The folder is a subfolder of a folder which is defined by the user together with the unique identifier in a dialog box. 

 

::result = Dialog(

v list( "Year 20XX", year=Edit Text("17",width(100))),

v list( "Identifier", iden=Edit Text("AA1211",width(100)))

);

The name of all subfolder have the same structure ABC-year-iden-xxxx bbb ddddd FFF.

ABC is fixed. year and iden are selected by the user but x b d F are variables.

 

I tried to get the filename with pick file but it does not work as last bit of it is variable.

Foldername = Pick file("\\Select folder","C:\Users\20"||::result["year"]||"\"||"ABC-"||::result["year"]||"-"||::result["iden"]||"-*");

 

Another option is reading the names of the subfolders in the main folder and try to match it but I cannot figure it out with regex.

files = Files In Directory("C:\Users\20"||::result["year"]);

The idea is once I have this folderpathname open a file in this folder with the same name as the subfolder. For that I have the script but I just am looking for a way to identify the subfolder pathway and filename.

 

Could someone help me out?

 

Thanks,

 

SC

1 ACCEPTED SOLUTION

Accepted Solutions
uday_guntupalli
Level VIII

Re: How do I open folder with unique identifier in name but variable ending?

 Maybe use Pick Directory() or you can declare it ahead and use the following 

 

RootFolder = "C:/" ;   // or Pick Directory() 
Year = 2005 ; 

SearchTerm = RootFolder || Char(Year) ; 
Best
Uday

View solution in original post

3 REPLIES 3
uday_guntupalli
Level VIII

Re: How do I open folder with unique identifier in name but variable ending?

@SC1

RootFolder = "C:\";  // Please fill in your desired folder location 

FileList = Files In Directory(RootFolder); // Extract list of all files

DesList = list(); // Declare empty list 

UserInput = 2005 ; 

for(i = 1, i <= N Items(FileList), i++,
		If(!IsMissing(Regex(Char(FileList[i]),Concat(Char(UserInput),"-","ABC|FFF")),
			Insert Into(DesList,FileList[i]); 
		  );
   );
// This will be able to capture all files which are of the format  2005-ABC or 2005-FFF . You can expand on the or clause based on your need 
Best
Uday
SC1
SC1
Level I

Re: How do I open folder with unique identifier in name but variable ending?

Thanks a lot. I see now how I get the name but how ca nI get the path of the folder?

uday_guntupalli
Level VIII

Re: How do I open folder with unique identifier in name but variable ending?

 Maybe use Pick Directory() or you can declare it ahead and use the following 

 

RootFolder = "C:/" ;   // or Pick Directory() 
Year = 2005 ; 

SearchTerm = RootFolder || Char(Year) ; 
Best
Uday