LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (August 2008)Back to main SPSSX-L pageJoin or leave SPSSX-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 20 Aug 2008 02:51:04 -0700
Reply-To:     fomcl@yahoo.com
Sender:       "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From:         Albert-jan Roskam <fomcl@yahoo.com>
Subject:      Re: Script/Macro/Syntax Help
Comments: To: Craig Johnson <cjohns38@gmail.com>
In-Reply-To:  <bfed04db0808191059h5d17499et363d6766fde0f0ce@mail.gmail.com>
Content-Type: text/plain; charset=us-ascii

Hi!

This is similar to some problem posted earlier this week. See the code below. One general question re: python: why is 'savlist' composed of elements of the form: d:/temp\\somefile.sav ....whereas 'savlist[i]' generates something like d:/temp\somefile.sav Notice the single backslash. How can I prevent this? I tried several options mentioned in os.path, but without result.

Cheers!! Albert-Jan

BEGIN PROGRAM. import spss import glob savlist = glob.glob("d:/temp/*.sav") if savlist: for i in range(len(savlist)): spss.Submit(""" get file = '%s'. insert file = 'c:/example/recode.sps'. save outfile = '%s_r.sav.' """ % (savlist[i], savlist[i][:-4])) else: print "Nothing to do" END PROGRAM.

--- On Tue, 8/19/08, Craig Johnson <cjohns38@gmail.com> wrote:

> From: Craig Johnson <cjohns38@gmail.com> > Subject: Script/Macro/Syntax Help > To: SPSSX-L@LISTSERV.UGA.EDU > Date: Tuesday, August 19, 2008, 7:59 PM > I am looking to create a script/macro/syntax to help me with > some analyses. > In essence, I need to open a series of files, run syntax on > each file, and > then save the altered file as FileName_R.sav. For example > say I have files > 1.sav, 2.sav, and 3.sav in the folder C:/example/ and want > to run a recode > on all the files using the following syntax file > C:/example/syntax/recode.sps. The code needs to open up > 1.sav, run > recode.sps, and then save the recoded file to 1_r.sav in > C:/example/recode/. > It would then open 2.sav, run recode.sps, and save the > recoded file. Finally, > it would open 3.sav, run recode.sps, and then save the > recoded file. > > The catch here is that the code needs to be generic so that > it works on all > the files in the folder. (Sorry merging them all together > isn't an > option). For example, the next time I run the syntax > folder C:/example/ may > include 4.sav, 5.sav, and 6.sav so the code needs to > account for that. > > Any ideas on how to accomplish this using some sort of > generic code? > > ===================== > To manage your subscription to SPSSX-L, send a message to > LISTSERV@LISTSERV.UGA.EDU (not to SPSSX-L), with no body > text except the > command. To leave the list, send the command > SIGNOFF SPSSX-L > For a list of commands to manage subscriptions, send the > command > INFO REFCARD

===================== To manage your subscription to SPSSX-L, send a message to LISTSERV@LISTSERV.UGA.EDU (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD


Back to: Top of message | Previous page | Main SPSSX-L page