Author Topic: Using File Objects, can I create a file through script?  (Read 1280 times)

Just wondering if I could do this.

If you open and write to a file that doesn't exist, it'll create it for you

Yes.
Code: [Select]
%file = new fileObject();
%file.openForWrite("Config/Server/whatever/file.cs");
%file.WriteLine("This is a line");
%file.close();
%file.delete();

Yes.
Code: [Select]
%file = new fileObject();
%file.openForWrite("Config/Server/whatever/file.cs");
%file.WriteLine("This is a line");
%file.close();
%file.delete();
%file.delete();
really

%file.delete();
really

It's not what you think it is. The function to delete a file is fileDelete("folder/file.txt"). What you're seeing there is the .delete() method that all objects have to remove them from memory. On line one, he creates a FileObject and stores it in %file, which is what he uses to handle opening the file for writing. Once he's done with it, he uses .delete() on the FileObject to clean up the memory since he doesn't need it anymore.

%file.delete();
really
It deletes the file object, not the file. You're thinking of fileDelete(%path);