Jump to content

Javascript to AutoIt | Working with Drives and Folders conversion


Glyph
 Share

Recommended Posts

;FileSystemObject (FSO) Working with Drives and Folders
;Converted from Javascript to AutoIt by Glyph
;Converted from http://msdn.microsoft.com/en-us/library/ch28h2s7(VS.85).aspx
$Path = "c:"
ShowDriveInfo($Path)
func ShowDriveInfo($drvPath)
   Dim $fso, $drv, $s
   $fso = ObjCreate("Scripting.FileSystemObject")
   $drv = $fso.GetDrive($fso.GetDriveName($drvPath))
   $s = "Drive " & $drvPath & " - "
   $s = $s & $drv.VolumeName & @crlf
   $s = $s & "Total Space: " & $drv.TotalSize / 1024
   $s = $s & " Kb" & @crlf
   $s = $s & "Free Space: " & $drv.FreeSpace / 1024
   $s = $s & " Kb" & @crlf
  msgbox(0,"",$s)
Endfunc

Original code:

function ShowDriveInfo1(drvPath)
{
   var fso, drv, s ="";
   fso = new ActiveXObject("Scripting.FileSystemObject");
   drv = fso.GetDrive(fso.GetDriveName(drvPath));
   s += "Drive " + drvPath.toUpperCase()+ " - ";
   s += drv.VolumeName + "<br>";
   s += "Total Space: " + drv.TotalSize / 1024;
   s += " Kb" + "<br>"; 
   s += "Free Space: " + drv.FreeSpace / 1024;
   s += " Kb" + "<br>";
   Response.Write(s);
}

Just thought I would share, i'm getting into javascript now :mellow:

tolle indicium

Link to comment
Share on other sites

I think this is a more accurate translation:

func ShowDriveInfo($drvPath)
   Dim $fso, $drv, $s
   $fso = ObjCreate("Scripting.FileSystemObject")
   $drv = $fso.GetDrive($fso.GetDriveName($drvPath))
   $s &= "Drive " & $drvPath & " - "
   $s &= $drv.VolumeName & @crlf
   $s &="Total Space: " & $drv.TotalSize / 1024
   $s &=" Kb" & @crlf
   $s &= "Free Space: " & $drv.FreeSpace / 1024
   $s &= " Kb" & @crlf
  msgbox(0,"",$s)
Endfunc
Link to comment
Share on other sites

Why make it more complicated than it has to be? :mellow:

Tell that to linux developers, it's similair because you're dictated by a command in autoit, you can control it more with WMI.

This is only an example, there are many more WMI scripts that autoit simply does not have (yet?).

For example, to detect a video card. I don't see a function in autoit for that, I see one in WMI though.

And so we are clear, WMI can be used in many languages.

With my example, a newbie can learn WMI and make his own script to detect video cards.

tolle indicium

Link to comment
Share on other sites

  • 2 weeks later...

WMI is great and I use it from time to time, a great tool is the Scriptomatic tool for AutoIt. However as far as I can see your script doesn't use WMI, but another object so it would be more correct to say the example show how to use objects and how to add additional functions to AutoIt.

Agreed, I was thinking of my other script while I write that reply, lol.

I was working on a script with a buddy of mine involving WMI and we got stuck on a couple things at the time, I was in the "WMI mindset". :mellow:

Scriptomatic is a very nice tool, easily adaptable to any script too!

tolle indicium

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...