However, you could first read the contents, change the contents, delete the file and save the modified contents under the old file name. Thanks Reuben - there are potentially hundreds of them, so am looking for a way to automate it, but maybe it is not possible? Well, sort of. I could rebuild it for you but I'd have to charge a couple of hours for that.
A basic way to change all items in a Python list is [i This technique is known as a Python list comprehension and the syntax below uses it to lowercase all variable names line Note: since I usually avoid all uppercasing in SPSS variable names, the result is identical to our case sensitive search. I you don't like that, the simple solution is to convert all variable names for all files to lower case. We'll simply check if it's present in our variable names list and -if so- print back the name of the data file. In this example, however, we'll simply look up which variables each file contains with spssaux. We could then add some syntax we'd like to run on each file. If we replace the file name with each of the paths in our Python list, we'll open each data file, one by one.
How to Execute Python Scripts in Batch Mode using Windows Task Scheduler However, having Python create full paths to our files with os. For doing anything whatsoever with our data files, we probably want to open them.įor doing so, SPSS needs to know in which folder they are located. Next, we'll add each file to this list if it endswith ".
The syntax below creates a Python list of files and folders in rDirour root directory. Try it for yourself by downloading spssfiles. The Python os for o perating s ystem module will do it for us. Running syntax over several SPSS data files in one go is fairly easy. How to Create a Batch File to Run Python Script