Process list of files with python

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

Process list of files with python

jfca283
Hi
I know how to process files under a certain folder with Python.
But i really don't know how to select only some of them by using a list.
Can you guide me?
Thanks.
Reply | Threaded
Open this post in threaded view
|

Re: Process list of files with python

Jignesh Sutar
Can you be more specic please.

Wouldn't you just want to check if that file exist in the list and if so then continue? Simple "if x in list then"?
Reply | Threaded
Open this post in threaded view
|

Re: Process list of files with python

jfca283
I have a list of files under my Documents folder. 60 files with zsav extension.
And i want to process only 5 of them:
amj_15.zsav
efm_15.zsav
amj_14.zsav
efm_14.zsav
ond_14.zsav

As you can see, the task is very simple. Except to me.
When i use the syntax, y use the GET FILE=!INPUTJOB but that order import every single file that belongs to the path i've specified, C/Users/Me/Documents.
I hope i made myself clear. If i didn't, i'm sorry.
Reply | Threaded
Open this post in threaded view
|

Re: Process list of files with python

Jignesh Sutar
Can you please share you attempts/syntax so far to execute this part of the process.
Reply | Threaded
Open this post in threaded view
|

Re: Process list of files with python

jfca283
This post was updated on .
Here is where i'm using the Python plugin named "SPSSINC PROCESS FILES" for processing a list of files:
SPSSINC PROCESS FILES INPUTDATA="C:\Users\Me\Documents\*.zsav"  
SYNTAX="C:\Users\Me\Documents\IC.sps" 
    CONTINUEONERROR=YES
VIEWERFILE= "C:\Users\Me\Desktop\VIEWER.spv" CLOSEDATA=YES
MACRONAME="!JOB" LOGFILEMODE=APPEND 
/MACRODEFS ITEMS.

And here is the IC.sps syntax that i'm applying to the files.
GET FILE="JOB_INPUTFILE".

 CSDESCRIPTIVES 
  /PLAN FILE='C:\Users\Me\Documents\MC.csaplan' 
  /RATIO NUMERATOR=d_D DENOMINATOR=PEA 
  /STATISTICS SE CV CIN(95) 
  /SUBPOP TABLE=Region DISPLAY=LAYERED 
  /MISSING SCOPE=ANALYSIS CLASSMISSING=EXCLUDE.

But i don't need to perform the IC.sps syntax over all the files under the Documents folder.
Only the ones i declared some posts above.
Thanks by the way for your help, interest and time.

Reply | Threaded
Open this post in threaded view
|

Re: Process list of files with python

Jignesh Sutar
I'm not sure if SPSSINC PROCESS FILES accepts regular use of RegEx. If so, you could try:

PSSINC PROCESS FILES INPUTDATA="C:\Users\Me\Documents\(amj_15|efm_15|amj_14|efm_14|ond_14).zsav"


Or some other RegEx expression which captures the files you do want to process vs those that you don't.
Reply | Threaded
Open this post in threaded view
|

Re: Process list of files with python

Art Kendall
In reply to this post by jfca283
If this were a one time task, I would simply write the syntax for the first file.
Then I would copy-and past it 4 times.
Then I would edit the few characters that change in the last 4 snippets.

This is doing essentially the same thing that a macro or python would do -- create new snippets of syntax with some elements of the snippet changed.

Depending on your operating system (OS) you could just create folder/directory with a name like "working_subset" and just copy the 5 files to that subset (or just create 5 links in that folder)

Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Re: Process list of files with python

Jon K Peck
In reply to this post by Jignesh Sutar
PROCESS files accepts wildcard expressions but not regular expressions.  I've found that users understand the former but not the latter, so I used wildcards.  A user can, however, create a text file listing the files to process.


Jon Peck (no "h") aka Kim
Senior Software Engineer, IBM
[hidden email]
phone: 720-342-5621




From:        Jignesh Sutar <[hidden email]>
To:        [hidden email]
Date:        10/23/2015 09:12 AM
Subject:        Re: [SPSSX-L] Process list of files with python
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




I'm not sure if SPSSINC PROCESS FILES accepts regular use of RegEx. If so,
you could try:

PSSINC PROCESS FILES
INPUTDATA="C:\Users\Me\Documents\(amj_15|efm_15|amj_14|efm_14|ond_14).zsav"


Or some other RegEx expression which captures the files you do want to
process vs those that you don't.



--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/Process-list-of-files-with-python-tp5730837p5730845.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
Reply | Threaded
Open this post in threaded view
|

Re: Process list of files with python

jfca283
And that file list must contain only the files with the path to them?
I mean like this?
C/Users/Me/Documents/file1.sav
C/Users/Me/Documents/file2.sav
C/Users/Me/Documents/file3.sav
C/Users/Me/Documents/file4.sav
Am i right?
Reply | Threaded
Open this post in threaded view
|

Re: Process list of files with python

Jon K Peck
In reply to this post by jfca283
You can use a list of files in the format produced by SPSSINC SPLIT FILES to specify exactly which files to process.  Here is an example of what the file might look like.  Note that the names must be in double quotes.

"c:\users\peck\appdata\local\temp\tmpvqbgc9\Clerical.sav"
"c:\users\peck\appdata\local\temp\tmpvqbgc9\Custodial.sav"
"c:\users\peck\appdata\local\temp\tmpvqbgc9\Manager.sav"


Jon Peck (no "h") aka Kim
Senior Software Engineer, IBM
[hidden email]
phone: 720-342-5621




From:        jfca283 <[hidden email]>
To:        [hidden email]
Date:        10/23/2015 10:38 AM
Subject:        [SPSSX-L] Process list of files with python
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




Hi
I know how to process files under a certain folder with Python.
But i really don't know how to select only some of them by using a list.
Can you guide me?
Thanks.



--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/Process-list-of-files-with-python-tp5730837.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
Reply | Threaded
Open this post in threaded view
|

Re: Process list of files with python

jfca283
It worked!
I just edited my syntax file as this:
SPSSINC PROCESS FILES  <b>FILELIST</b>="C:\Users\Me\Documents\List.txt"
SYNTAX="C:\Users\Me\Documents\IC.sps" OUTPUTDATADIR="C:\Users\Me\Documents\Desktop" 
    CONTINUEONERROR=YES
VIEWERFILE= "C:\Users\Me\Documents\Desktop\ss" CLOSEDATA=YES
MACRONAME="!JOB" LOGFILEMODE=APPEND
/MACRODEFS ITEMS.
And the List.txt file contain the files i'll process as this:
"C:\Users\Me\Documents\file1.sav"
"C:\Users\Me\Documents\file2.sav"
...
"C:\Users\Me\Documents\fileN.sav"