Tutorial: How to read/write using the FileSystem! :) - Printable Version -Shoutbox (https://shoutbox.menthix.net) +-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58) +--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4) +---- Forum: Scripting (/forumdisplay.php?fid=39) +----- Thread: Tutorial: How to read/write using the FileSystem! :) (/showthread.php?tid=79504) Tutorial: How to read/write using the FileSystem! :) by Toneo on 11-30-2007 at 09:15 PM
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.
Useful resources: 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: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: If you try it and it says "false" then it can mean two things...
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: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: 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! RE: Tutorial: How to edit the FileSystem! :) by Deco on 11-30-2007 at 09:37 PM
Nice work! RE: Tutorial: How to edit the FileSystem! :) by CookieRevised on 12-01-2007 at 12:30 AM
Excellent to the point tutorial ... RE: Tutorial: How to edit the FileSystem! :) by Toneo on 12-01-2007 at 09:21 AM Okay. Thanks for the pointers, i'm glad you like the tutorial. RE: Tutorial: How to edit the FileSystem! :) by vikke on 12-01-2007 at 02:52 PM
I think the phrase "How to edit the File System" sounds pretty wierd. The File System type (on Windows NT and above) is NTFS (NT File System), you're not changing it, you're reading and writing from it. RE: Tutorial: How to read/write using the FileSystem! :) by absorbation on 12-01-2007 at 04:52 PM Great tutorial. I suggest you add a link in the scripting tips thread . RE: Tutorial: How to read/write using the FileSystem! :) by Toneo on 12-01-2007 at 09:11 PM Thanks. I've changed it from how to "edit the filesystem" to how to "read/write using the filesystem" which makes much more sense, and i've also added the link to the scripting tips thread. RE: Tutorial: How to read/write using the FileSystem! :) by Crazed on 12-01-2007 at 10:16 PM Nice tutorial. I'll find this comes in handy. RE: Tutorial: How to read/write using the FileSystem! :) by vikke on 12-02-2007 at 10:56 AM Also, note: To get the path to the Windows folder, no matter what it's called, call the GetSystemWindowsDirectory API using Interop.Call(). |