What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Tutorial: How to read/write using the FileSystem! :)

Tutorial: How to read/write using the FileSystem! :)
Author: Message:
Toneo
Junior Member
**

Avatar
Epic.

Posts: 35
Reputation: 2
28 / Male / Flag
Joined: Jul 2007
O.P. Grin  Tutorial: How to read/write using the FileSystem! :)
Okay. So this is a tutorial on how to edit the FileSystem. Some of your scripters out there will know how, but some of you don't, which is why i've made this tutorial for you.

I will explain...
  • How to check for files and folders
  • How to delete files and folders
  • How to create files and folders

Useful resources:
  • JScript Documentation [Link]
  • Scripting Tips Thread [Link]

Believe it or not, it's actually very easy to access and edit the FileSystem.
Okay. First of all, we need to declare an ActiveXObject() to access the FileSystem...

code:
var fileSys = new ActiveXObject("Scripting.FileSystemObject");
Wow! Great! We've accessed the file system! Well, actually, all we've done is declared an object accessible via the variable fileSys that doesn't do anything. Yet.

This code checks if the folder WINDOWS exists in the C:\ directory and displays the result to the user through MsgPlus.DisplayToast(). Please be very careful with this. If you edit this to create or delete files in the WINDOWS folder, you could damage your system!

code:
var fileSys = new ActiveXObject("Scripting.FileSystemObject");
MsgPlus.DisplayToast("FileSystem",fileSys.FolderExists("C:\\WINDOWS\\"));

If you try it and it says "false" then it can mean two things...

  • You've entered the code incorrectly
    OR
  • The WINDOWS directory doesn't exist (It can have different names such as WINNT!)

Syntax for FolderExists: Object.FolderExists([string]Path);
Note: You can also have FileExists().

Both FolderExists() and FileExists() are both VERY useful in scripts, you can use them to detect whether a file already exists.

Note:
They also have bugs. They will not always return the proper boolean. Be very careful when you use those functions to check for empty directories, files with the same name as a directory, null-files, etc.

Okay. So, straight onto creating files!


code:
var fileSys = new ActiveXObject("Scripting.FileSystemObject");
var fileSysFile = fileSys.CreateTextFile("C:\\fileSys.txt",true);
fileSysFile.WriteLine("FileSystem!!!");
fileSysFile.Close();
Run this code, then have a look in your C:\ directory. You should see a file called fileSys.txt. If not then you've entered the code incorrectly. Open it, and you should see "Filesystem!!!" written inside.
That's great. It means we can create files to store information!

Note: Use Close() to close the file, if you don't you might do something wrong. But nothing's gone wrong for me so far.

Syntax for CreateTextFile: Object.CreateTextFile([string]Path,[boolean]overwrite);
Overwrite: True or false - If true, it will overwrite any file already there, if false, then if a file already exists then an error may occur.


Now onto deleting files. Please be careful with this method, in case you make a mistake and destroy half your filesystem. :)

code:
var fileSys = new ActiveXObject("Scripting.FileSystemObject");
fileSys.DeleteFile("C:\\fileSys.txt",false);

Nice and easy one. If you input it correctly you should no longer see the file fileSys.txt we created in the section on creating files.
If you've added ReadOnly attributes to fileSys.txt then it shouldn't be gone.

Syntax for DeleteFile: Object.DeleteFile([string]Path,[boolean]force);
force: If true, files with ReadOnly attributes will be deleted, if false, then if the file is ReadOnly it will be left alone.

If you have anything to add to this tutorial please say so! I know that my tutorial isn't perfect.
I hope this tutorial helps you! :D

This post was edited on 12-01-2007 at 09:10 PM by Toneo.
[Image: signature-user=291&back=4&clr=12,102,237&size=80.png]
11-30-2007 09:15 PM
Profile E-Mail PM Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
Tutorial: How to read/write using the FileSystem! :) - by Toneo on 11-30-2007 at 09:15 PM
RE: Tutorial: How to edit the FileSystem! :) - by Deco on 11-30-2007 at 09:37 PM
RE: Tutorial: How to edit the FileSystem! :) - by CookieRevised on 12-01-2007 at 12:30 AM
RE: Tutorial: How to edit the FileSystem! :) - by Toneo on 12-01-2007 at 09:21 AM
RE: Tutorial: How to edit the FileSystem! :) - by vikke on 12-01-2007 at 02:52 PM
RE: Tutorial: How to read/write using the FileSystem! :) - by absorbation on 12-01-2007 at 04:52 PM
RE: Tutorial: How to read/write using the FileSystem! :) - by Toneo on 12-01-2007 at 09:11 PM
RE: Tutorial: How to read/write using the FileSystem! :) - by Crazed on 12-01-2007 at 10:16 PM
RE: Tutorial: How to read/write using the FileSystem! :) - by vikke on 12-02-2007 at 10:56 AM


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On