Creating and placing files within a directory

The use of specific JADE features and proposals for new feature suggestions
User avatar
ghosttie
Posts: 181
Joined: Sat Aug 15, 2009 1:25 am
Location: Atlanta, GA, USA
Contact:

Re: Creating a Directory and placing files withing that dire

Postby ghosttie » Sat Sep 21, 2013 2:14 am

Instead of

Code: Select all

file.mode := File.Mode_Output;
use

Code: Select all

file.mode := File.Mode_Append;
I have a catapult. Give me all the money or I will fling an enormous rock at your head.

M45HY
Posts: 63
Joined: Wed Jul 11, 2012 7:32 am
Location: Mansfield, Nottinghamshire, UK

Re: Creating a Directory and placing files withing that dire

Postby M45HY » Sat Sep 21, 2013 2:40 am

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?
"If you can't explain it simply, you don't understand it well enough." - Albert Einstein

User avatar
ghosttie
Posts: 181
Joined: Sat Aug 15, 2009 1:25 am
Location: Atlanta, GA, USA
Contact:

Re: Creating a Directory and placing files withing that dire

Postby ghosttie » Sat Sep 21, 2013 2:46 am

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?
I have a catapult. Give me all the money or I will fling an enormous rock at your head.

M45HY
Posts: 63
Joined: Wed Jul 11, 2012 7:32 am
Location: Mansfield, Nottinghamshire, UK

Re: Creating a Directory and placing files withing that dire

Postby M45HY » Sat Sep 21, 2013 2:50 am

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...
"If you can't explain it simply, you don't understand it well enough." - Albert Einstein

User avatar
ghosttie
Posts: 181
Joined: Sat Aug 15, 2009 1:25 am
Location: Atlanta, GA, USA
Contact:

Re: Creating a Directory and placing files withing that dire

Postby ghosttie » Sat Sep 21, 2013 2:53 am

Use file.writeLine instead of writeString
I have a catapult. Give me all the money or I will fling an enormous rock at your head.

M45HY
Posts: 63
Joined: Wed Jul 11, 2012 7:32 am
Location: Mansfield, Nottinghamshire, UK

Re: Creating a Directory and placing files withing that dire

Postby M45HY » Sat Sep 21, 2013 3:02 am

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! :D
"If you can't explain it simply, you don't understand it well enough." - Albert Einstein

murray
Posts: 144
Joined: Fri Aug 14, 2009 6:58 pm
Location: New Plymouth, New Zealand

Re: Creating a Directory and placing files withing that dire

Postby murray » Sat Sep 21, 2013 3:11 pm

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.
Murray (N.Z.)

murray
Posts: 144
Joined: Fri Aug 14, 2009 6:58 pm
Location: New Plymouth, New Zealand

Re: Creating a Directory and placing files withing that dire

Postby murray » Sat Sep 21, 2013 8:44 pm

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.
Murray (N.Z.)

allistar
Posts: 156
Joined: Fri Aug 14, 2009 11:02 am
Location: Mount Maunganui, Tauranga

Re: Creating a Directory and placing files withing that dire

Postby allistar » Mon Sep 23, 2013 9:19 am

Try:

Code: Select all

file.mode := File.Mode_Append;

M45HY
Posts: 63
Joined: Wed Jul 11, 2012 7:32 am
Location: Mansfield, Nottinghamshire, UK

Re: Creating a Directory and placing files withing that dire

Postby M45HY » Mon Sep 23, 2013 9:31 pm

Thanks allistar and murray. ghosttie's method worked perfectly.

Cheers guys
"If you can't explain it simply, you don't understand it well enough." - Albert Einstein


Return to “Feature Discussions”

Who is online

Users browsing this forum: No registered users and 20 guests