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
%3CLINGO-SUB%20id%3D%22lingo-sub-585140%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3Epulling%20information%20with%20date%20condition%3A%20put%20filename%20into%20list%20if%20it%20is%20greater%20than%20a%20specified%20date%20and%20time%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-585140%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3EI%20m%20trying%20to%26nbsp%3B%20get%20the%20list%20of%20files%20name%20in%20a%20directory%20with%20given%20condition%20if%20it%20is%201)%20zip%20archive%20and%20also%20the%202)%20creation%20date%20greater%20than%20yyyy%2Fmm%2Fdd.%20Below%20is%20my%20script.%20My%20question%3C%2FP%3E%3CP%3E1)%20it%20ran%20without%20error%20but%20not%20return%20empty%20list.%20I%20'm%20not%20sure%20what%20is%20the%20issue%20(perhaps%20the%20date).%3CBR%20%2F%3E2)%20how%20can%20I%20set%20the%20creation%20date%20()%20output%20format%20to%20yyyy%2Fmm%2Fdd%20hh%3Amm%3Ass%3F%26nbsp%3B%3C%2FP%3E%3CP%3E3)%20it%20take%20long%20time%20to%20loop%20through%20the%20path2%20because%20I%20have%20over%20100K%20zip%20folders.%20Is%20there%20other%20faster%20way%20to%20do%20it%3F%3C%2FP%3E%3CP%3EThanks%3C%2FP%3E%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3Epath2%20%3D%20%22C%3A%5CUsers%5Ctest%5C%3B%0Afilelist%20%3D%20files%20in%20directory%20(path2)%3B%0Alst2%20%3D%20%7B%7D%3B%0AFor(i%3D1%2C%20i%26lt%3B%3D%20N%20items(filelist)%2C%20i%2B%2B%2C%0AIf(%20Contains(filelist%5Bi%5D%2C%20%22.zip%22)%20%26amp%3B%20Creation%20Date(%20path2%7C%7Cfilelist%5Bi%5D)%20%26gt%3B%202022-10-12T08%3A00%3A00%2C%20Insert%20Into(%20lst2%2C%20filelist%5Bi%5D%20)%0A)%2C%0A)%3B%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-585140%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CLINGO-LABEL%3EScripting%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-585161%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20pulling%20information%20with%20date%20condition%3A%20put%20filename%20into%20list%20if%20it%20is%20greater%20than%20a%20specified%20date%20and%20time%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-585161%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EIn%20the%20example%20you%20provided%2C%20there%20is%20a%20missing%20double%20quote%20on%20the%20path2%20%3D%26nbsp%3B%20%26nbsp%3B%20line%2C%20and%20also%2C%20the%20time%20reference%20does%20not%20seem%20to%20be%20handling%20by%20JMP%2C%20so%20by%20changing%20it%20to%20an%20Informat()%20function%2C%20one%20can%20be%20insured%20that%20the%20JMP%20Date%2FTime%20reference%20is%20being%20interpreted%20correctly.%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3Enames%20default%20to%20here(1)%3B%0Apath2%20%3D%20%22C%3A%5CUsers%5Ctest%5C%22%3B%0Afilelist%20%3D%20Files%20In%20Directory(%20path2%20)%3B%0Alst2%20%3D%20%7B%7D%3B%0AFor(%20i%20%3D%201%2C%20i%20%26lt%3B%3D%20N%20Items(%20filelist%20)%2C%20i%2B%2B%2C%0A%20If(%20Contains(%20filelist%5Bi%5D%2C%20%22.zip%22%20)%20%26amp%3B%20Creation%20Date(%20path2%20%7C%7C%20filelist%5Bi%5D%20)%20%26gt%3B%20informat(%222022-10-12T08%3A00%3A00%22%2C%20%22yyyy-mm-ddThh%3Amm%3Ass%22)%2C%0A%20%20Insert%20Into(%20lst2%2C%20filelist%5Bi%5D%20)%0A%20)%0A)%3B%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-585196%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20pulling%20information%20with%20date%20condition%3A%20put%20filename%20into%20list%20if%20it%20is%20greater%20than%20a%20specified%20date%20and%20time%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-585196%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EHi%20Jim%2C%20Thanks.%20that%20fixed%20the%20problem.%20However%2C%20it%20take%20too%20much%20time%20when%20a%20folder%20has%20too%20many%20files%20to%20go%20through.%20Below%20are%20the%20new%20steps%20I%20have%20so%20next%20time%20when%20I%20just%20want%20to%20pull%20the%20latest%20files%2C%20it%20don't%20take%20the%20long%20time%20like%20using%20the%20date%2Ftime%20as%20filter%20(above).%20I%20'm%20not%20sure%20if%20it%20is%20an%20effective%20way%20to%20do%20it.%20Is%20there%20any%20better%20way%20to%20just%20extract%20latest%20files%20with%20shorter%20time%3F%3C%2FP%3E%3CP%3E1)%20the%20first%20time%20get%20the%20whole%20filelist%20in%20the%20defined%20folder%20(%3CSPAN%3EFiles%20In%20Directory(dir)%3C%2FSPAN%3E).%20Saved%20it%20into%20a%20column%20of%20a%20table%2C%20%22T1%22%20(only%20run%20one%20time)%3C%2FP%3E%3CP%3E2)%20after%20sometime%2C%20latest%20files%20added%20to%20the%20same%20folder.%20script%20will%20go%20to%20the%20same%20folder%20and%20take%20the%20whole%20filelist%20as%20%22newlist%22%20(newlist%20%3D%26nbsp%3B%3CSPAN%3EFiles%20In%20Directory(dir))%3C%2FSPAN%3E.%3C%2FP%3E%3CP%3E3)%20get%20column%20in%20table%201)%20as%20list%2C%20then%20loop%20through%20to%20remove%20the%20elements%20out%20from%20newlist%20(I%20use%20Remove%20From%20())%20.%3C%2FP%3E%3CP%3E4)%20do%20whatever%20needed%20on%20newlist.%3C%2FP%3E%3CP%3E5)%20append%20newlist%20into%20table%20in%201).%3C%2FP%3E%3CP%3E6)%20repeat%20step%202)-5)%20next%20time%20when%20I%20need%20to%20get%20latest%20files%20again.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAny%20suggestion%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-585197%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20pulling%20information%20with%20date%20condition%3A%20put%20filename%20into%20list%20if%20it%20is%20greater%20than%20a%20specified%20date%20and%20time%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-585197%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EYou%20could%20try%20this....it%20should%20speed%20it%20up%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3ENames%20Default%20To%20Here(%201%20)%3B%0Apath2%20%3D%20%22C%3A%5CUsers%5Ctest%5C%22%3B%0Afilelist%20%3D%20Files%20In%20Directory(%20path2%20)%3B%0AFor(%20i%20%3D%20N%20Items(%20filelist%20)%2C%20i%20%26gt%3B%3D%201%2C%20i--%2C%0A%20If(%20Right(%20filelist%5Bi%5D%2C%204%20)%20!%3D%20%22.zip%22%2C%0A%20%20Remove%20From(%20filelist%2C%20i%2C%201%20)%0A%20)%0A)%3B%0Alst2%20%3D%20%7B%7D%3B%0AFor(%20i%20%3D%201%2C%20i%20%26lt%3B%3D%20N%20Items(%20filelist%20)%2C%20i%2B%2B%2C%0A%20If(%20Creation%20Date(%20path2%20%7C%7C%20filelist%5Bi%5D%20)%20%26gt%3B%20informat(%222022-10-12T08%3A00%3A00%22%2C%20%22yyyy-mm-ddThh%3Amm%3Ass%22)%2C%0A%20%20Insert%20Into(%20lst2%2C%20filelist%5Bi%5D%20)%0A%20)%0A)%3B%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E
Choose Language Hide Translation Bar
dadawasozo
Level IV

pulling information with date condition: put filename into list if it is greater than a specified date and time

Hi,

I m trying to  get the list of files name in a directory with given condition if it is 1) zip archive and also the 2) creation date greater than yyyy/mm/dd. Below is my script. My question

1) it ran without error but not return empty list. I 'm not sure what is the issue (perhaps the date).
2) how can I set the creation date () output format to yyyy/mm/dd hh:mm:ss? 

3) it take long time to loop through the path2 because I have over 100K zip folders. Is there other faster way to do it?

Thanks

path2 = "C:\Users\test\;
filelist = files in directory (path2);
lst2 = {};
For(i=1, i<= N items(filelist), i++,
If( Contains(filelist[i], ".zip") & Creation Date( path2||filelist[i]) > 2022-10-12T08:00:00, Insert Into( lst2, filelist[i] )
),
);

 

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
txnelson
Super User

Re: pulling information with date condition: put filename into list if it is greater than a specified date and time

In the example you provided, there is a missing double quote on the path2 =    line, and also, the time reference does not seem to be handling by JMP, so by changing it to an Informat() function, one can be insured that the JMP Date/Time reference is being interpreted correctly.

names default to here(1);
path2 = "C:\Users\test\";
filelist = Files In Directory( path2 );
lst2 = {};
For( i = 1, i <= N Items( filelist ), i++,
	If( Contains( filelist[i], ".zip" ) & Creation Date( path2 || filelist[i] ) > informat("2022-10-12T08:00:00", "yyyy-mm-ddThh:mm:ss"),
		Insert Into( lst2, filelist[i] )
	)
);
Jim

View solution in original post

txnelson
Super User

Re: pulling information with date condition: put filename into list if it is greater than a specified date and time

You could try this....it should speed it up

Names Default To Here( 1 );
path2 = "C:\Users\test\";
filelist = Files In Directory( path2 );
For( i = N Items( filelist ), i >= 1, i--,
	If( Right( filelist[i], 4 ) != ".zip",
		Remove From( filelist, i, 1 )
	)
);
lst2 = {};
For( i = 1, i <= N Items( filelist ), i++,
	If( Creation Date( path2 || filelist[i] ) > informat("2022-10-12T08:00:00", "yyyy-mm-ddThh:mm:ss"),
		Insert Into( lst2, filelist[i] )
	)
);
Jim

View solution in original post

3 REPLIES 3
txnelson
Super User

Re: pulling information with date condition: put filename into list if it is greater than a specified date and time

In the example you provided, there is a missing double quote on the path2 =    line, and also, the time reference does not seem to be handling by JMP, so by changing it to an Informat() function, one can be insured that the JMP Date/Time reference is being interpreted correctly.

names default to here(1);
path2 = "C:\Users\test\";
filelist = Files In Directory( path2 );
lst2 = {};
For( i = 1, i <= N Items( filelist ), i++,
	If( Contains( filelist[i], ".zip" ) & Creation Date( path2 || filelist[i] ) > informat("2022-10-12T08:00:00", "yyyy-mm-ddThh:mm:ss"),
		Insert Into( lst2, filelist[i] )
	)
);
Jim
dadawasozo
Level IV

Re: pulling information with date condition: put filename into list if it is greater than a specified date and time

Hi Jim, Thanks. that fixed the problem. However, it take too much time when a folder has too many files to go through. Below are the new steps I have so next time when I just want to pull the latest files, it don't take the long time like using the date/time as filter (above). I 'm not sure if it is an effective way to do it. Is there any better way to just extract latest files with shorter time?

1) the first time get the whole filelist in the defined folder (Files In Directory(dir)). Saved it into a column of a table, "T1" (only run one time)

2) after sometime, latest files added to the same folder. script will go to the same folder and take the whole filelist as "newlist" (newlist = Files In Directory(dir)).

3) get column in table 1) as list, then loop through to remove the elements out from newlist (I use Remove From ()) .

4) do whatever needed on newlist.

5) append newlist into table in 1).

6) repeat step 2)-5) next time when I need to get latest files again.

 

Any suggestion?

txnelson
Super User

Re: pulling information with date condition: put filename into list if it is greater than a specified date and time

You could try this....it should speed it up

Names Default To Here( 1 );
path2 = "C:\Users\test\";
filelist = Files In Directory( path2 );
For( i = N Items( filelist ), i >= 1, i--,
	If( Right( filelist[i], 4 ) != ".zip",
		Remove From( filelist, i, 1 )
	)
);
lst2 = {};
For( i = 1, i <= N Items( filelist ), i++,
	If( Creation Date( path2 || filelist[i] ) > informat("2022-10-12T08:00:00", "yyyy-mm-ddThh:mm:ss"),
		Insert Into( lst2, filelist[i] )
	)
);
Jim