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 (February 2010)Back to main SPSSX-L pageJoin or leave SPSSX-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Sat, 20 Feb 2010 03:03:38 -0800
Reply-To:   Albert-Jan Roskam <fomcl@yahoo.com>
Sender:   "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From:   Albert-Jan Roskam <fomcl@yahoo.com>
Subject:   Re: file date stamp as a variable
Comments:   To: Maurice Vergeer <m.vergeer@maw.ru.nl>
In-Reply-To:   <4c2416b1002200135p86ee577r2618057675c00482@mail.gmail.com>
Content-Type:   multipart/alternative;

Hi Maurice,

That's quite easy with Python. The code below should do what you want, even though it's untested. I'm pretty sure that it works, but you need to give the command that you use to read the txt file (do they have a separator? are they fixed width files?). And of course, you need to set the correct dir (remember to prefix it with r"  if you use backslashes.)

BEGIN PROGRAM. import os, time, glob, spss

txts = glob.glob("d:/temp/*.txt") for cnt, txt in enumerate(txts):   mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime = os.stat(txt)   stamp = time.strftime("%Y-%m-%d", time.localtime(mtime)) # last modification date of the file   spss.Submit("get file = '%s'." % txt) # --- replace this with your GET DATA command, use triple quotes if needed ---.   spss.Submit("string moddate (a10).\ncompute moddate = %s." % stamp)   if cnt == 0:    spss.Submit("save outfile = 'd:/temp/merged.sav'.")      elif cnt % 50 == 0:     pct = float((cnt+1)) / len(txts)     spss.Submit("echo '** Processing file %s of %s (%4.2f%%)'." % (cnt+1, len(txts), pct)     spss.Submit("add files / file = 'd:/temp/merged.sav' / file = *.")     spss.Submit("save outfile = 'd:/temp/merged.sav'.")   else:     spss.Submit("add files / file = 'd:/temp/merged.sav' / file = *.")     spss.Submit("xsave outfile = 'd:/temp/merged.sav'.") # use XSAVE here spss.Submit("sort cases by moddate.") spss.Submit("save outfile = 'd:/temp/merged.sav'.") END PROGRAM.

Cheers!! Albert-Jan ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In the face of ambiguity, refuse the temptation to guess. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

--- On Sat, 2/20/10, Maurice Vergeer <m.vergeer@maw.ru.nl> wrote:

From: Maurice Vergeer <m.vergeer@maw.ru.nl> Subject: [SPSSX-L] file date stamp as a variable To: SPSSX-L@LISTSERV.UGA.EDU Date: Saturday, February 20, 2010, 10:35 AM

dear list members

I have about 1400 small text files that need to be converted to one single system file (sav). I found a way to do this on the spsstools.net site. However, I also want to include the time stamp of these text files (time and date the file was created on disc) as a variable in the system file. Is there a way to do this in an automated way?

thanks Maurice Vergeer

-- ___________________________________________________________________ Maurice Vergeer Department of communication Radboud University  (www.ru.nl) PO Box 9104 NL-6500 HE Nijmegen The Netherlands

Visiting Professor Yeungnam University, Gyeongsan, South Korea

contact: E: m.vergeer@maw.ru.nl T: +31 24 3612297 (direct)/ 3612372 (secretary) / maurice.vergeer (skype) personal webpage: www.mauricevergeer.nl blog:  http://blog.mauricevergeer.nl/ Journalism: www.journalisteninhetdigitaletijdperk.nl CENMEP New Media and European Parliament Elections 2009 http://mauricevergeer.ruhosting.nl/cenmep

Recent publications: - Vergeer, M. & Pelzer, B. (2009). Consequences of media and Internet use for offline and online network capital and well-being. A causal model approach. Journal of Computer-Mediated Communication, 15, 189-210. -Vergeer, M., Coenders, M. & Scheepers, P. (2009). Time spent on television in European countries. In R.P. Konig, P.W.M. Nelissen, & F.J.M. Huysmans (Eds.), Meaningful media: Communication Research on the Social Construction of Reality (54-73). Nijmegen, The Netherlands: Tandem Felix. - Hermans, L., Vergeer, M., &  d’Haenens, L. (2009). Internet in the daily life of journalists. Explaining the use of the Internet through work-related characteristics and professional opinions. Journal of Computer-Mediated Communication, 15, 138-157. - Hermans, L., Vergeer, M., & Pleijter, A. (2009). Internet Adoption in the Newsroom: Journalists’ use of the Internet explained by Attitudes and Perceived Functions. Communications. The European Journal of Communication, 34(1), 55-71. - Vergeer, M., & Hermans, L. (2008). Analyzing online political discussions: Methodological considerations. Javnost/The Public, 15(2), 37-56. ___________________________________________________________________

===================== 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


[text/html]


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