Subscribe Bookmark RSS Feed

JSL how to delete folders based on LastModificationDate

MuttonChops

Occasional Contributor

Joined:

Mar 30, 2017

Hi, using JMP Pro 13.0.  I am a JSL newbie so I know my coding isn't super efficient but I just need functionality for some personal scripts.  I have a lenghtly script and in this one part I'm in need of copying a directory from another drive to a local work drive.  First I purge the local work drive then do the copy.  I don't want to copy the entire directory, just folders within that are -N days old.  Is this possible?  And "DirA" and "DirB" of course are substitutes for my drive locations.

SPath = "DirA";
LPath = "DirB";
LSubPath = "DirB"||"\DirC";
Delete Directory( LSubPath );
//Below is where I would like to only copy folders within SPath that are -N days old
Copy Directory (SPath, LPath);
1 ACCEPTED SOLUTION

Accepted Solutions
mpl34

Community Trekker

Joined:

Feb 16, 2016

Solution

Can you copy files based on their creation date? This might be too slow as for only a few thousand files it took ~30s to generate a list (not copy).

 

Something like below:

namesdefaulttohere(1);
filelist=filesindirectory("DirA");
for(i=1,i<length(filelist),i++,
	if(datedifference(creationdate("DirA\"||filelist[i]),today(),"Day","fractional")<10,
		copyfile("DirA\"||filelist[i],"DirB")
	);
);

 

 

 

 

 

2 REPLIES
mpl34

Community Trekker

Joined:

Feb 16, 2016

Solution

Can you copy files based on their creation date? This might be too slow as for only a few thousand files it took ~30s to generate a list (not copy).

 

Something like below:

namesdefaulttohere(1);
filelist=filesindirectory("DirA");
for(i=1,i<length(filelist),i++,
	if(datedifference(creationdate("DirA\"||filelist[i]),today(),"Day","fractional")<10,
		copyfile("DirA\"||filelist[i],"DirB")
	);
);

 

 

 

 

 

MuttonChops

Occasional Contributor

Joined:

Mar 30, 2017

namesdefaulttohere(1);
filelist=filesindirectory("DirA");
for(i=1,i<length(filelist),i++,
	if(datedifference(creationdate("DirA\"||filelist[i]),today(),"Day","fractional")<10,
		copyfile("DirA\"||filelist[i],"DirB\"||filelist[i])
);
);

That worked, I made one tiny change at the end...seems I have to specify the file name in DirB in the copyfile function. 

 

Thanks!!