Morning, I came up with this. Thanks for your help.
dataset close all.
set unicode=YES.
NEW FILE.
DATASET NAME DataSet1 WINDOW=FRONT.
BEGIN PROGRAM python3.
import os
import shutil
import glob
import spss
mypath = "C:/datab/2022/*Active*"
ActivePath=(max(glob.glob(mypath), key=os.path.getmtime))
print(ActivePath)
target =r'C:\datab\2022\current\active_current.sav'
shutil.copyfile(ActivePath,target)
end program.
set unicode=off.
------------------------------
Art Jack
------------------------------
Original Message:
Sent: Mon December 13, 2021 03:34 PM
From: Jon Peck
Subject: Using most recent file with common name structure
If you have some control over the file naming, you might consider using the CreateFileNameWDate and FindMostRecentFile functions in the spssaux2.py module shipped with Statistics. These expect a sortable date string, which the format you show does not without some care in the naming.
The doc for the second function says,
Return the full filename, including path if included in basename,
of the most recent file matching basename or None if there is no match.
Matching means the filename equals the basename with or without a timestamp.
A timestamp has the format
_YYYY-MM-DD_HH-MM
just before the extension.
which could then be opened with code in the BEGIN PROGRAM block, or that code could create a macro to be used outside that program.
If you can't control the date string, more elaborate code would be required to parse the date and then select from the qualifying files.
--
Original Message:
Sent: 12/13/2021 3:24:00 PM
From: Art Jack
Subject: Using most recent file with common name structure
Afternoon, I'm trying to write something that I can put into SPSS production. I need to pull in the most recent version of whatever file is available, without having to go in and actually change the name. For the active file if there is a more recent version I need to use that one. Thanks in advance.
dataset close all.
get file='e:\data\2022\active 11 29 2021.sav'.
------------------------------
Art Jack
------------------------------
#SPSSStatistics