|
Dear all,
I wanted to identify all .sps files in my folder and subfolders that contain any HOST command. My program does render a couple of .sps files which all contain at least one HOST command. However, it seems as if these are all syntax files created by version 15 or older (which are readable with notepad, whereas 16+ seems to require wordpad). For the sake of the experiment, I created a little syntax file with a HOST command in V17 and it was -indeed- not identified as an .sps file containing a HOST command. Could anyone suggest how I could modify my program to include version 16+ syntax as well? TIA! Ruben van den Berg Consultant Models & Methods TNS NIPO Email: [hidden email] Mobiel: +31 6 24641435 Telefoon: +31 20 522 5738 Internet: www.tns-nipo.com begin program. import os def app(path): paths = [] for dp, ds, fs in os.walk(path): for f in fs: paths.append(os.path.join(dp,f)) return paths end program. begin program. paths=app('/Copy_Syn') targets=[] for path in paths: file=open(path,"r") for line in file: if "HOST".lower() in line: targets.append(path) print "\n".join(targets) end program. New Windows 7: Find the right PC for you. Learn more. |
|
V16 files are no different in format from earlier syntax files, although they could be in Unicode. Unicode would not affect recognition of plain ascii text such as HOST, though. But the code below lower cases "HOST" and then searches each line for "host". I'd do it the other way around: lower case line and search for "host" Also, note that os.walk is designed to return files one by one, so you could do the searching within the loop in the first program. HTH, Jon Peck SPSS, an IBM Company [hidden email] 312-651-3435
Dear all, I wanted to identify all .sps files in my folder and subfolders that contain any HOST command. My program does render a couple of .sps files which all contain at least one HOST command. However, it seems as if these are all syntax files created by version 15 or older (which are readable with notepad, whereas 16+ seems to require wordpad). For the sake of the experiment, I created a little syntax file with a HOST command in V17 and it was -indeed- not identified as an .sps file containing a HOST command. Could anyone suggest how I could modify my program to include version 16+ syntax as well? TIA! Ruben van den Berg Consultant Models & Methods TNS NIPO Email: [hidden email] Mobiel: +31 6 24641435 Telefoon: +31 20 522 5738 Internet: www.tns-nipo.com begin program. import os def app(path): paths = [] for dp, ds, fs in os.walk(path): for f in fs: paths.append(os.path.join(dp,f)) return paths end program. begin program. paths=app('/Copy_Syn') targets=[] for path in paths: file=open(path,"r") for line in file: if "HOST".lower() in line: targets.append(path) print "\n".join(targets) end program. New Windows 7: Find the right PC for you. Learn more. |
|
Oh, I see! The problem is that
if "HOST".lower() in line: should have been if "host" in line.lower(): And now it indeed renders my V17 test file as well! Well, at least I seem to have a talent for looking in the wrong places when my code doesn't work... Thanks a lot for helping out again! Ruben van den Berg Consultant Models & Methods TNS NIPO Email: [hidden email] Mobiel: +31 6 24641435 Telefoon: +31 20 522 5738 Internet: www.tns-nipo.com To: [hidden email] CC: [hidden email] Subject: Re: [SPSSX-L] Can Python read .sps files created by versions 16+? From: [hidden email] Date: Fri, 23 Jul 2010 06:54:38 -0600 V16 files are no different in format from earlier syntax files, although they could be in Unicode. Unicode would not affect recognition of plain ascii text such as HOST, though. But the code below lower cases "HOST" and then searches each line for "host". I'd do it the other way around: lower case line and search for "host" Also, note that os.walk is designed to return files one by one, so you could do the searching within the loop in the first program. HTH, Jon Peck SPSS, an IBM Company [hidden email] 312-651-3435
Dear all, I wanted to identify all .sps files in my folder and subfolders that contain any HOST command. My program does render a couple of .sps files which all contain at least one HOST command. However, it seems as if these are all syntax files created by version 15 or older (which are readable with notepad, whereas 16+ seems to require wordpad). For the sake of the experiment, I created a little syntax file with a HOST command in V17 and it was -indeed- not identified as an .sps file containing a HOST command. Could anyone suggest how I could modify my program to include version 16+ syntax as well? TIA! Ruben van den Berg Consultant Models & Methods TNS NIPO Email: [hidden email] Mobiel: +31 6 24641435 Telefoon: +31 20 522 5738 Internet: www.tns-nipo.com begin program. import os def app(path): paths = [] for dp, ds, fs in os.walk(path): for f in fs: paths.append(os.path.join(dp,f)) return paths end program. begin program. paths=app('/Copy_Syn') targets=[] for path in paths: file=open(path,"r") for line in file: if "HOST".lower() in line: targets.append(path) print "\n".join(targets) end program. New Windows 7: Find the right PC for you. Learn more. New Windows 7: Find the right PC for you. Learn more. |
|
| Free forum by Nabble | Edit this page |
