What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Get File Size

Get File Size
Author: Message:
neohunter
Junior Member
**


Posts: 38
Joined: Aug 2006
O.P. Get File Size
Buenas =D!

Hi, i want to get the file size of a file...

im downloading a image from internet and want to put it as display picture, i generate the image on the server side using GD library, normally everithing its ok, but sometimes failed and the script returns me a error. so i want to check the filesize before put it as display picture.

this is what i think that should work...

var fileso = new ActiveXObject("Scripting.FileSystemObject");
fileso.GetFile("C:\\dp.jpg");
MsgPlus.DisplayToast("UnionRo 2.0","FileSize: " + fileso.Size);

But retuns me a message say: Filesize: undefeined

whats the problem? any other way to obtain the file size? may using wscript.shell ?
09-15-2006 05:10 PM
Profile E-Mail PM Find Quote Report
CookieRevised
Elite Member
*****

Avatar

Posts: 15519
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: Get File Size
The problem is that you perform the method GetFile() but you don't assign the returned file object to a variable.

And the Size property is a member of a file object, not a member of a file system object.

Thus:
code:
var fileso = new ActiveXObject("Scripting.FileSystemObject");
var file = fileso.GetFile("C:\\dp.jpg");
MsgPlus.DisplayToast("UnionRo 2.0","FileSize: " + file.Size);
Also note that the code doesn't take in account file errors which may occur. eg: if the file "C:\\dp.jpg" doesn't exist for example.

So better would be:
code:
var fileName = "C:\\dp.jpg";
var fileSystemObject = new ActiveXObject("Scripting.FileSystemObject");
if (fileSystemObject.FileExists(fileName)) {
        var fileObject = fileSystemObject.GetFile(fileName);
        MsgPlus.DisplayToast("UnionRo 2.0","FileSize: " + fileObject.Size);
} else {
        MsgPlus.DisplayToast("UnionRo 2.0","File does not exist");
}

and made a bit shorter:
code:
var fileName = "C:\\dp.jpg";
var fileSystemObject = new ActiveXObject("Scripting.FileSystemObject");
if (fileSystemObject.FileExists(fileName)) {
        MsgPlus.DisplayToast("UnionRo 2.0","FileSize: " + GetFile(fileName).Size);
} else {
        MsgPlus.DisplayToast("UnionRo 2.0","File does not exist");
}



;)

This post was edited on 09-15-2006 at 05:30 PM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
09-15-2006 05:14 PM
Profile PM Find Quote Report
neohunter
Junior Member
**


Posts: 38
Joined: Aug 2006
O.P. RE: Get File Size
HAHAHA! WORKS!! THANKS YOU VERY MUCH =)
09-15-2006 05:22 PM
Profile E-Mail PM Find Quote Report
« Next Oldest Return to Top Next Newest »


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