Jump to content
Sign in to follow this  
celestialspring

Read CSV and split per line

Recommended Posts

celestialspring

Hi Guys,

The script I am trying to write it simple:

Read a CSV file, say Test.CSV

Split it per line then save each line to a file by the name of Test1.csv, Test2.csv and so on...

I have been able to write only until this point (see below) any ideas what I should be doing next?

=======BEGIN============

#Include <file.au3>

$fileorg = "c:\test.csv"

FileOpen($fileorg)

Dim $aRecords

$linenumbercount = _FileCountLines($fileorg)

$fileread = _FileReadToArray($fileorg,$aRecords)

For $x = 1 to $aRecords

_FileWriteFromArray(????)

============END====================

Thanks. CS

Share this post


Link to post
Share on other sites
JackDinn

Morning ;)

#include <file.au3>
$fileorg = "test.csv"
FileOpen($fileorg, 0)
Dim $aRecords[100]
$fileread = _FileReadToArray($fileorg, $aRecords)
FileClose($fileorg)
For $x = 1 To $aRecords[0]
    FileWrite("test" & $x & ".csv", $aRecords[$x])
Next
Edited by JackDinn

Thx all,Jack Dinn.

 

JD's Auto Internet Speed Tester

JD's Clip Catch (With Screen Shot Helper)

Projects :- AutoIt - My projects

My software never has bugs. It just develops random features. :-D

Share this post


Link to post
Share on other sites
celestialspring

A very good morning to you too sir.

Thank you very much. The script works perfectly ;)

Share this post


Link to post
Share on other sites
Tvern

It works, but there are still a few unneeded elements in it. This should be an improvement:

edit:The script in the next post is even better. Mine actually had a pretty stupid mistake in it.

Edited by Tvern

Share this post


Link to post
Share on other sites
JackDinn

ahh, i was sure there was a shorter way to do this (as i said, it was far to early for me)

#include <file.au3>
$fileorg = "test.csv"
$file = FileOpen($fileorg, 0)
For $x = 1 To _FileCountLines($fileorg)
    FileWrite("test" & $x & ".csv", FileReadLine($file))
Next
FileClose($fileorg)

thats the shortest i can get it without getting silly (which this is really ;))


Thx all,Jack Dinn.

 

JD's Auto Internet Speed Tester

JD's Clip Catch (With Screen Shot Helper)

Projects :- AutoIt - My projects

My software never has bugs. It just develops random features. :-D

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×