Creating and placing files within a directory

The use of specific JADE features and proposals for new feature suggestions
M45HY
Posts: 63
Joined: Wed Jul 11, 2012 7:32 am
Location: Mansfield, Nottinghamshire, UK

Creating and placing files within a directory

Postby M45HY » Thu Jun 13, 2013 4:05 am

Hi guys,

Just had a quick question. I'm basically trying to access a directory and if the directory doesn't exist, I wish to create that directory. For example, if I'm trying to access "C:\Windows\New Folder" but the folder "New Folder" does not exist, I wish to create it. Also, I have currently created a report that creates a Comma Seperated Value (CSV) file. Once that file has been created, I would like to place it (i.e) within the directory as mentioned above.

If anyone knows how to do this or they have done it before, it would be a great help if you could share your wisdom :D

Thanks,
Omash
Last edited by M45HY on Wed Sep 25, 2013 2:42 am, edited 2 times in total.
"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 » Thu Jun 13, 2013 5:06 am

Code: Select all

vars folderDest : FileFolder; begin create folderDest transient; folderDest.fileName := sDestFolder; if not folderDest.isAvailable then folderDest.make; endif; end;
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 » Fri Jun 14, 2013 8:55 pm

Hi ghosttie,

Thanks mate, that worked like a charm! Just had a quick question though, as I mentioned above, if I created a .csv file would it store it in the location that I have specified or would I have to apply another set of coding to move that file in to the destination I want?

Thanks,
Omash
"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 » Fri Jun 14, 2013 10:47 pm

What do you mean by creating a file: Creating it by Jade code, or externally (e.g. by saving from Excel)?

If creating via Jade code using the File class, it "puts" it wherever you specify in the fileName.
You can specify a file path name, e.g. "C:\temp\extracts\myfile.csv".
Murray (N.Z.)

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 » Fri Jun 14, 2013 11:51 pm

Hi murray,

Sorry, I was a bit unclear here. I did mean creating a .csv file using Jade.

The way that I am using Jade for this is by creating a set of coding that will create the .csv file (e.g. Code A) and a completely separate piece of coding that moves and renames the file (Code B). Code B is called when Code A has completed. I did it this way rather than putting both sets of coding into one group because I am getting a time delay issue, where Code B is not moving and renaming the file because Code A hasn’t yet produced the physical file.

I would like the .csv file to be created, moved and renamed in one set of coding (e.g. Code A) but as mentioned above, I’m getting the delay problem. At the moment, I was using something called setTitle() (not 100% sure whether it is a global method in JADE or something that my predecessors have created) which renames the file but I was unable to rename the file and move it to a specific destination.

I hope that clears up some of the misconceptions. Thanks,
Omash
"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 Jun 15, 2013 1:35 am

You could have Code A generate a string containing the contents of your CSV and then save it to a file using code like this:

Code: Select all

vars file : File; begin create file transient; file.kind := File.Kind_ANSI; file.shareMode := File.Share_Exclusive; file.mode := File.Mode_Output; file.allowCreate := true; file.fileName := pS_FileName; file.open; file.writeString(pS_ToSave); epilog if file <> null and file.isOpen then file.close; endif; delete file; end;
Or if you just want to move an existing file you could use an external function (which should be less resource intensive than loading the source file using one File object and saving it using a second File object):

Code: Select all

copyFile(sourceFileName : String; destFileName : String; failIfExists : Boolean) : Boolean is CopyFileA in kernel32;
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 Jun 15, 2013 3:56 am

Hi ghosttie,

Just had a quick question in regards to your reply. I was just trying to understand the first part of the coding that you did. In that example, would I define the 'file.fileName' as being the directory and/or the name of the .csv file?

For example:

Code: Select all

file.fileName := "C:\Windows\New Folder"; // Just directory file.fileName := "File.csv"; // Just File Name file.fileName := "C:\Windows\New Folder\File.csv"; // Both Directory and File Name
Also, would the 'pS_ToSave' be the String of information that (in this case) I would want to write in to File.csv?

Sorry about this; I'm still trying to get use to Jade. Thanks,
Omash
"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 Jun 15, 2013 4:57 am

This one:

Code: Select all

file.fileName := "C:\Windows\New Folder\File.csv"; // Both Directory and File Name
Also, would the 'pS_ToSave' be the String of information that (in this case) I would want to write in to File.csv?
Yes
I have a catapult. Give me all the money or I will fling an enormous rock at your head.

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 Jun 15, 2013 3:08 pm

Hi Omash,

These issues are not Jade-specific, but are generic to all standard file handling.
The Jade file I/O routines are probably just re-implementations of the core O/S routines.
You will encounter similar coding in many other languages.

The topics of creating, opening, reading, writing, and appending files all fall under the general heading of "File Input and Output (I/O)". You may be able to find a good tutorial that covers these topics and fills in some more details.

The Jade manuals with descriptions of the File, FileNode and FileFolder classes will help you, once you know what it is that you want to do.
Murray (N.Z.)

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

Re: Creating a Directory and placing files within that direc

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

Hi guys,

Sorry for the late response; I thought this problem had left me but it came back with vengeance!

Code: Select all

vars file : File; begin create file transient; file.kind := File.Kind_ANSI; file.shareMode := File.Share_Exclusive; file.mode := File.Mode_Output; file.allowCreate := true; file.fileName := pS_FileName; file.open; file.writeString(pS_ToSave); epilog if file <> null and file.isOpen then file.close; endif; delete file; end;
This coding above (with a huge thanks to ghosttie :D ) works perfectly, however, the method in which this coding lies within is called upon several times i.e. Method 1 will retrieve the data from the appropriate location and will store it into a string and then calls Method 2, which writes the line of data into the file. But at the end of the program, only a single line is outputted to the file and I'm assuming that this is happening as the system is opening the file and writing on top of what's there rather than creating a new line/row. How can I do this? Would I have to concatenate the existing data with the new data or do I have to do something else?

Thanks,
Omash
"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 1 guest

cron