Page 2 of 2
Re: Creating a Directory and placing files withing that dire
Posted: Sat Sep 21, 2013 2:14 am
by ghosttie
Re: Creating a Directory and placing files withing that dire
Posted: Sat Sep 21, 2013 2:40 am
by M45HY
I tried that but when I try opening it in MS Excel, it says "File not loaded completely"...
.. I just checked and what happens is that instead of putting out a new row (as this will be a .csv file) it adds it on to the end of the data already there so rather than creating rows of data, it's creating columns of data. Any other suggestions?
Re: Creating a Directory and placing files withing that dire
Posted: Sat Sep 21, 2013 2:46 am
by ghosttie
That's a strange error, I don't think I've seen that before.
If you open it in a text editor what do you see?
Re: Creating a Directory and placing files withing that dire
Posted: Sat Sep 21, 2013 2:50 am
by M45HY
In a text editor, the data is seperated by commas but it is continous as if the data is one long line.
E.g.
Rather than:
Row 1: Emp1, Forename, Surname, Address 1, Address 2, Address 3, Address 4...
Row 2: Emp2, Forename, Surname, Address 1, Address 2, Address 3, Address 4...
It's doing this:
Row 1: Emp1, Forename, Surname, Address 1, Address 2, Address 3, Address 4...Emp2, Forename, Surname, Address 1, Address 2, Address 3, Address 4...
Re: Creating a Directory and placing files withing that dire
Posted: Sat Sep 21, 2013 2:53 am
by ghosttie
Use file.writeLine instead of writeString
Re: Creating a Directory and placing files withing that dire
Posted: Sat Sep 21, 2013 3:02 am
by M45HY
ghosttie... I love you mate!
It worked like a charm! Gosh, this was bugging me since the beginning of 2013!
I couldn't have done it without you!

Re: Creating a Directory and placing files withing that dire
Posted: Sat Sep 21, 2013 3:11 pm
by murray
Hi Omash,
When you open a file in "output" mode it always overwrites existing content, i.e. clears data and creates a "new" file from the start. The alternative is "append" mode which will begin writing output after the last byte in the file.
You have a couple of alternatives:
(1) Open the file with mode = Mode_Append.
(2) Use one single File object, open the file with mode = Mode_Output and pass the File object to each method that needs to write lines to the file (or assign it to a class property if that suits the design). While continuously open in this mode the lines will be appened to the end of the file.
Option (1) needs careful thought if multi-threading is involved, as the file is only locked while it is open in Exclusive sharing mode. At other times it can be accessed by any process. This may be exactly what you want (shared access), or not desirable, depending on you design requirements.
Option (2) may be better if you have a need for exclusive acces to the one file.
Re: Creating a Directory and placing files withing that dire
Posted: Sat Sep 21, 2013 8:44 pm
by murray
Oops, sorry, I hadn't noticed that the thread had gone onto the second page!
Looks like it all got resolved OK in the end.
Re: Creating a Directory and placing files withing that dire
Posted: Mon Sep 23, 2013 9:19 am
by allistar
Re: Creating a Directory and placing files withing that dire
Posted: Mon Sep 23, 2013 9:31 pm
by M45HY
Thanks allistar and murray. ghosttie's method worked perfectly.
Cheers guys