I am trying to figure out a way to tell spss syntax to run itself on all files in a certain directory and then either create one large file where the outputs are merged or to create separate output files. A friend sent me this script which seems to work in python but I am having trouble using it in SPSS:
for files in os.listdir("."):
f = open(files)
outPutOfF = f.read()
work = open("C:/Users/kang/processed/" + files + "_workfile.txt", "a")
work.write( "Content of outPutOfF is: " + outPutOfF )
The script that I made with spss syntax is designed to open individual files, format them correctly, derive a mean, and then save an output of each individual file. The problem is that I have to change the name of the file that it is accessing each time I run it, so that it will eventually run all of the files I need it to. However, I would like this process automated. The spss syntax script I use is:
/FILE='F:\Form & Motion Discrimination\RAW\10005_dir.txt'
DATASET NAME DataSet1 WINDOW=FRONT.
SELECT IF Trial = 45 OR Trial = 46 OR Trial = 47 OR Trial = 48 OR Trial = 49 OR Trial = 50.
SAVE OUTFILE = 'F:\Form & Motion Discrimination\Data\RAW\10005_dir.sav'
GET FILE='F:\Form & Motion Discrimination\Data\RAW\10005_dir.sav'.
/OUTFILE='F:\Form & Motion Discrimination\Data\TEMP\RT.sav'
/RT = MEAN(Vis).
Any suggestions would be appreciated. I have some experience using the spss syntax but very little experience with python.
Oh and I am using spss 20.