Files

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

Files

luciano basso
Hi Team,

I need to open 500 files (.TXT) with 2000 lines and mergies them into
only one file, I also add a variable in line of each file - I will use
the name of the open file.

Please suggest a syntax.

Thanks,

Luciano Basso,
São Paulo University
Motor Behavior Labotory
Brazil - São Paulo

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

Bruce Weaver
Administrator
luciano basso wrote
Hi Team,

I need to open 500 files (.TXT) with 2000 lines and mergies them into
only one file, I also add a variable in line of each file - I will use
the name of the open file.

Please suggest a syntax.

Thanks,

Luciano Basso,
São Paulo University
Motor Behavior Labotory
Brazil - São Paulo
I think you need to give more information, Luciano.  E.g., is there some systematic pattern to the file names (e.g., file001.txt, file002.txt, ... file500.txt)?  Are they all stored in the same folder?  What is your operating system?  I expect a macro can be written to do what you want, but how exactly one would go about it depends on the answers to some of these questions.

Cheers,
Bruce
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

PLEASE NOTE THE FOLLOWING: 
1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.
2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/).
Reply | Threaded
Open this post in threaded view
|

Re: Files

Albert-Jan Roskam
hi!

Very similar to a previous post (http://www.listserv.uga.edu/cgi-bin/wa?A2=ind0909&L=spssx-l&O=A&P=30880)

Untested, but more or less or perhaps even entirely correct :-)

import glob, os.path
path = "d:/temp"
txts = glob.glob(os.path.join(path, "*.txt"))
merged = os.path.join(path, "merged.txt")
outfile = open(merged, "ab")
for txt in sorted(txts):
    infile = open(os.path.join(path, txt), "rb")
    for row in infile:
        outfile.write(os.path.basename(txt) + "\t" + row)
infile.close()
outfile.close()

Cheers!!
Albert-Jan


--- On Tue, 9/29/09, Bruce Weaver <[hidden email]> wrote:

> From: Bruce Weaver <[hidden email]>
> Subject: Re: [SPSSX-L] Files
> To: [hidden email]
> Date: Tuesday, September 29, 2009, 6:17 PM
> luciano basso wrote:
> >
> > Hi Team,
> >
> > I need to open 500 files (.TXT) with 2000 lines and
> mergies them into
> > only one file, I also add a variable in line of each
> file - I will use
> > the name of the open file.
> >
> > Please suggest a syntax.
> >
> > Thanks,
> >
> > Luciano Basso,
> > São Paulo University
> > Motor Behavior Labotory
> > Brazil - São Paulo
> >
> >
>
> I think you need to give more information, Luciano.
> E.g., is there some
> systematic pattern to the file names (e.g., file001.txt,
> file002.txt, ...
> file500.txt)?  Are they all stored in the same
> folder?  What is your
> operating system?  I expect a macro can be written to
> do what you want, but
> how exactly one would go about it depends on the answers to
> some of these
> questions.
>
> Cheers,
> Bruce
>
>
> -----
> --
> Bruce Weaver
> [hidden email]
> http://sites.google.com/a/lakeheadu.ca/bweaver/
> "When all else fails, RTFM."
>
> NOTE:  My Hotmail account is not monitored regularly.
> To send me an e-mail, please use the address shown above.
> --
> View this message in context: http://www.nabble.com/Files-tp25665502p25666136.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