I am using SPSS 19 und would like to get the current working directory to use the INSERT command, to call additional syntax files. Does somebody know how to do it? There seems to be a Python command (SpssClient.GetCurrentDirectory()) but that returns a gibberish error code (I love this pile of crap called SPSS....)
Rather than using the scripting API's, you can use the programmabilty API's like this.
begin program.
import spss, spssaux
workingdir = spssaux.getShow("DIRECTORY")
spss.Submit("""FILE HANDLE cwd /NAME="%s".""" % workingdir)
end program.
This defines a file handle named cwd
.
Note also that INSERT
has a CD
keyword that changes the backend working directory to whatever location is specified in FILE
.
HTH, Jon Peck
After some googling I found a working method:
BEGIN PROGRAM.
import spss
import SpssClient
CONST_FHandleName = 'CurrentDir'
#SpssClient.StartClient() /stop nötig, sonst gibt es Probleme mit dem zugriff auf SPSS
try:
SpssClient.StartClient()
syntaxpath =SpssClient.GetDesignatedSyntaxDoc()
currentdir = os.path.dirname(syntaxpath.GetDocumentPath())
FHandle="File handle " + CONST_FHandleName + " /name='" + currentdir + "'"
finally:
SpssClient.StopClient()
print "The FHandle Dir is now: " + currentdir
print "The FHandle Dir is now: " + FHandle
spss.Submit(FHandle)
END PROGRAM.
This program will get the directory of the current Syntax-File and set the directory as a file handle. Of course, this is not the real working directory, but a approximation that works for me.
Caution:
spss.getworkingdirectory returns apparently the first startup folder - NOT the folder of the active dataset (great if you startet SPSS first and then loaded the dataset - it will still point to its home directory, where it cannot write. SPSS 19 behaviour...)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With