cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
] />

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
Daron8
Level I

JSL: Filtering files by Creation Date with Files In Directory and Filter Each

Hi all,

I am working with JSL to collect and filter files from a directory.
The basic filtering logic (name, extension, size) works correctly, but I am running into issues when trying to add a reliable Creation Date filter.

This code correctly finds non‑empty .txt files whose names contain "result":

 

Names Default To Here(1);

folderPath = "C:/Users/.../test";
fileListOrig = Files In Directory(folderPath, Recursive(1));
fileList = Filter Each({v, i}, fileListOrig,
    Contains(v, "result") &
    Ends With(v, ".txt") &
    File Size(folderPath || v) > 0
);

// Data Cleaning
For( i = 1, i <= N Items( fileList ), i++,
    fileName = fileList[i];
...

What is the recommended or reliable way in JSL to filter files by creation date on Windows when combining Files In Directory with Filter Each?

Thanks,

 

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: JSL: Filtering files by Creation Date with Files In Directory and Filter Each

Build your dates (different ways, see date-time functions: JSL Syntax Reference > JSL Functions, Operators, and Messages > Date and Time Functions ), use file path with creation date (note if your folder ends with "/" or not when building the path) and add comparison

Names Default To Here(1);

folder = Convert File Path("$SAMPLE_DATA");

sdate = Date DMY(1,1,2025);
edate = Date DMY(31,3,2026);
flist = Files In Directory(folder, Recursive(1)); filtered_files = Filter Each({filename}, flist, Contains(filename, "Data") & Ends With(filename, ".jmp") & File Size(folder || filename) > 0 & sdate <= Creation Date(folder || filename) <= edate );
-Jarmo

View solution in original post

4 REPLIES 4
jthi
Super User

Re: JSL: Filtering files by Creation Date with Files In Directory and Filter Each

Use Creation Date()

jthi_0-1777384067549.png

Difficult to give any suggestion on what to combine it with as you didn't provide any ideas of the logic you are going for.

-Jarmo
Daron8
Level I

Re: JSL: Filtering files by Creation Date with Files In Directory and Filter Each

Thanks Jarmo — let me clarify.

What I am trying to do is filter files by a creation date range on top of the other filters (for example, files created between 2026‑01‑01 and 2026‑03‑31).

I have tried using Creation Date() in several ways (including examples from the User Community), but I was not sure how to combine it with Files In Directory() and Filter Each(), hence none of those worked.

Could you please show an example of how this should be done correctly?

-Aron

txnelson
Super User

Re: JSL: Filtering files by Creation Date with Files In Directory and Filter Each

Something like:

Names Default To Here(1);

folderPath = "C:/Users/.../test";
fileListOrig = Files In Directory(folderPath, Recursive(1));
fileList = Filter Each({v, i}, fileListOrig,
    Contains(v, "result") &
    Ends With(v, ".txt") &
    creation date(v) < informat("01052026", "MMDDYYYY") &
    creation date(v) >= informat("01052025", "MMDDYYYY") &
    File Size(folderPath || v) > 0
);

// Data Cleaning
For( i = 1, i <= N Items( fileList ), i++,
    fileName = fileList[i];
...
Jim
jthi
Super User

Re: JSL: Filtering files by Creation Date with Files In Directory and Filter Each

Build your dates (different ways, see date-time functions: JSL Syntax Reference > JSL Functions, Operators, and Messages > Date and Time Functions ), use file path with creation date (note if your folder ends with "/" or not when building the path) and add comparison

Names Default To Here(1);

folder = Convert File Path("$SAMPLE_DATA");

sdate = Date DMY(1,1,2025);
edate = Date DMY(31,3,2026);
flist = Files In Directory(folder, Recursive(1)); filtered_files = Filter Each({filename}, flist, Contains(filename, "Data") & Ends With(filename, ".jmp") & File Size(folder || filename) > 0 & sdate <= Creation Date(folder || filename) <= edate );
-Jarmo

Recommended Articles