|
Hi, I'm wondering how i would go about converting a series of .sav files into .dat files, while keeping their same names as they are. I hope this is clear: I wan't to loop a save translate command through a whole folder, set type to tab, and somehow have the outfile i.e. new name be generated automatically from the old name - but of course with the new extension. so
eqS40n5cat.sav -> eqS40n5cat.dat eqS40n6cat.sav -> eqS40n6cat.dat eqS40n7cat.sav -> eqS40n7cat.dat etc. so the question is how to refer to the file's name in syntax? thanks guys! maja |
|
Hi
Here is a python solution. All you need to do is replace "C:/Program Files/SPSS/" (in the last line of the PROGRAM block) by the path of your folder. The *.dat files are saved in the same folder as the existing sav files. Regards -- Raynald Levesque www.spsstools.net BEGIN PROGRAM. #convert all sav files into tab delimited file import spss, glob, os.path def exportToDat(folder): savlist = glob.glob(folder) nbConverted = 0 for fname in savlist: stem=os.path.basename(fname) fpath=os.path.abspath(fname) spss.Submit(""" GET FILE='%(fname)s'. SAVE TRANSLATE OUTFILE='%(fpath)s%(stem)s.dat' /TYPE=TAB /MAP /REPLACE /FIELDNAMES /CELLS=VALUES. """ % locals()) nbConverted += 1 print "Number of sav files converted:", nbConverted exportToDat(folder=r"C:/Program Files/SPSS/*.sav") END PROGRAM. On Mon, May 19, 2008 at 5:07 PM, maiya <[hidden email]> wrote: > Hi, I'm wondering how i would go about converting a series of .sav files > into > .dat files, while keeping their same names as they are. I hope this is > clear: I wan't to loop a save translate command through a whole folder, set > type to tab, and somehow have the outfile i.e. new name be generated > automatically from the old name - but of course with the new extension. so > eqS40n5cat.sav -> eqS40n5cat.dat > eqS40n6cat.sav -> eqS40n6cat.dat > eqS40n7cat.sav -> eqS40n7cat.dat > etc. > so the question is how to refer to the file's name in syntax? > thanks guys! > maja > -- > View this message in context: > http://www.nabble.com/save-translate-to-existing-file-name--tp17328219p17328219.html > Sent from the SPSSX Discussion mailing list archive at Nabble.com. > > ===================== > To manage your subscription to SPSSX-L, send a message to > [hidden email] (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 [hidden email] (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 |
|
Thanks Rayland!
Unfortunatley I have never worked with python, and was really hoping this can be done through regular spss syntax. The whole reason for my wish to batch translate these files is becasue I'm switching my analysis to R, and hopefuly never looking back. So can I do this using just syntax? Thanks again! Maja
|
|
Sorry about that, I changed my mind about being closed-minded about python and went ahead and installed it. Your code works quite well, with the exception that the final filenames are "doubled" so I got from:
taeeqInt5cat40n.sav to taeeqInt5cat40n.savtaeeqInt5cat40n.sav.dat after changing SAVE TRANSLATE OUTFILE='%(fpath)s%(stem)s.dat' into SAVE TRANSLATE OUTFILE='%(fpath)s.dat' the result is better: taeeqInt5cat40n.sav.dat but i would still like the extension (.sav) out of the name? Thanks again! Maja
|
| Free forum by Nabble | Edit this page |
