Jump to content

Read CSV and split per line


Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...