Get File Size - 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: Get File Size (/showthread.php?tid=66279)
Get File Size by neohunter on 09-15-2006 at 05:10 PM
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 ?
RE: Get File Size by CookieRevised on 09-15-2006 at 05:14 PM
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");
}
RE: Get File Size by neohunter on 09-15-2006 at 05:22 PM
HAHAHA! WORKS!! THANKS YOU VERY MUCH =)
|