View Full Version : File.Create
dwenco
12-24-2008, 12:26 PM
There's a folder.create function but I can't find any file.create function (to create a new file). It would be good to have that. Thanks.
Ulrich
12-24-2008, 01:14 PM
Hi,
what kind of file do you want o create?
ASCII/Text file - use TextFile.WriteFromString();
XML file - use XML.Save();
INI file - use INIFile.SetValue();
Ulrich
dwenco
12-26-2008, 08:41 PM
Thanks. I wanted to create both a new text file and a XML file. The Textfile.writefromstring would work for me for the text file. Sorry I was looking under "file" for the create option.
For creating a new XML file, however, XML.Save() saves whatever I have already loaded (using XML.Load) into the file I specify, unless I save it right at the beginning before I have loaded anything. If I create a blank XML file using textfile.writefromstring, I get an error loading this new blank xml file using xml.load.
I see that this is a suggestions forum, so maybe I should move it to the discussion forum...
Thanks.
Ulrich
12-26-2008, 10:57 PM
For creating a new XML file, however, XML.Save() saves whatever I have already loaded (using XML.Load) into the file I specify, unless I save it right at the beginning before I have loaded anything. If I create a blank XML file using textfile.writefromstring, I get an error loading this new blank xml file using xml.load.
Although you can create a skeleton XML as a text file first, it seems to me that there is no need for it. Here I show you how I created a simple XML from scratch...
-- create new XML skeleton
XML.SetXML("<?xml version=\"1.0\"?>\n<myxml>\n<creator>TrueUpdate 3.0</creator>\n</myxml>\n");
-- create first node
XML.InsertXML("myxml/creator", "<data>\n<name>John Doe</name>\n</data>\n", XML.INSERT_AFTER);
-- insert more data
XML.InsertXML("myxml/data/name", "<address>123 Somewere Road</address>\n", XML.INSERT_AFTER);
-- insert more data
XML.InsertXML("myxml/data/name", "<city>Demotown</city>\n", XML.INSERT_AFTER);
-- create second node
XML.InsertXML("myxml/data", "<data>\n<name>Jane Smith</name>\n</data>\n", XML.INSERT_AFTER);
-- insert more data
XML.InsertXML("myxml/data:2/name", "<address>456 Windy Ave</address>\n", XML.INSERT_AFTER);
-- insert more data
XML.InsertXML("myxml/data:2/name", "<city>Smallville</city>\n", XML.INSERT_AFTER);
-- create third node
XML.InsertXML("myxml/data:2", "<data>\n<name>Joe Sixpack</name>\n</data>\n", XML.INSERT_AFTER);
-- insert more data
XML.InsertXML("myxml/data:3/name", "<address>789 NW 8th Ave</address>\n", XML.INSERT_AFTER);
-- insert more data
XML.InsertXML("myxml/data:3/name", "<city>Ontario</city>\n", XML.INSERT_AFTER);
-- save XML file somewhere
XML.Save("D:\\temp\\test.xml");
Ulrich
dwenco
12-27-2008, 09:17 PM
Thanks a lot Ulrich. It works. This would solve my problem!:D
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.