cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
bzanos
Level III

Open Files in Directory based on a List of Variable Filenames

Hi all,

 

I have a list of filename. This list of filename is variable and change from to time. I want to match these file name to the files available in a directory. If match , open the files. 

I write below code and run it. It does not work.

Need guidance here.

 

 

folder = "C:\savefile\";

filename ={"Jan", "Feb", "Mar"};

filelist= Files In Directory(folder);

For(i=1, i<= N items(filename), i++,

   If (Contains(filename[i], "filelist"),
		Open (folder || filename[i] ||".jmp"))
	
);
1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: Open Files in Directory based on a List of Variable Filenames

I had to do couple of modifications.

1. Contains should have list as first argument and the filelist should not be in quotes

2. You have to concatenate .jmp to filelist

 

This slightly modified modified example should give you an idea what to modify:

folder = "C:\Program Files\SAS\JMPEA\17\Samples\Data\";
filename = {"AdverseR", "Air Traffic", "Abrasion"};
filelist = Files In Directory(folder);
For(i = 1, i <= N Items(filename), i++, 
	If(Contains(filelist, filename[i] ||".jmp"),
		Open(folder || filename[i] || ".jmp")
	);
);
-Jarmo

View solution in original post

4 REPLIES 4
txnelson
Super User

Re: Open Files in Directory based on a List of Variable Filenames

Are the actual file names you are looking for, named "Jan" or "Feb" or "Mar"?  or, are you looking for those month abbreviations to be part of the file name?

A sample of what the actual filenames are would be helpful.

Jim
bzanos
Level III

Re: Open Files in Directory based on a List of Variable Filenames

Jim, the file name is "Jan" or "Feb" or "Mar"

jthi
Super User

Re: Open Files in Directory based on a List of Variable Filenames

I had to do couple of modifications.

1. Contains should have list as first argument and the filelist should not be in quotes

2. You have to concatenate .jmp to filelist

 

This slightly modified modified example should give you an idea what to modify:

folder = "C:\Program Files\SAS\JMPEA\17\Samples\Data\";
filename = {"AdverseR", "Air Traffic", "Abrasion"};
filelist = Files In Directory(folder);
For(i = 1, i <= N Items(filename), i++, 
	If(Contains(filelist, filename[i] ||".jmp"),
		Open(folder || filename[i] || ".jmp")
	);
);
-Jarmo
bzanos
Level III

Re: Open Files in Directory based on a List of Variable Filenames

Thank you, Jarmo. It works.