Command Line - Help

Page 2 of 2 FirstFirst 12

  1. Posts : 5,092
    Windows 7 32 bit
       #11

    Here's the source to df if you want to adapt it. The WinApiEx include file has all the API calls you need. It's included with AutoIt3 download package I believe.
    On second thought I get compile errors. Constants already defined. So best to stick to vbscript? Hehe.
      My Computer


  2. Posts : 5,092
    Windows 7 32 bit
       #12

    OK. I had a munged install of AutoIt3 that gave errors. I uninstalled it and installed the latest stable version and the Scite4AutoIt3 editor. These are free tools. Both may be downloaded here:https://www.autoitscript.com/site/autoit/downloads/

    I compiled and ran this source successfully on both a Windows 7 x64 VM and on native Windows 8.0 x64. No errors or warnings.

    Here's the source

    Code:
    #Region ;**** Directives created by AutoIt3Wrapper_GUI ****
    #AutoIt3Wrapper_Icon=HD.ico
    #AutoIt3Wrapper_Outfile=df.exe
    #AutoIt3Wrapper_Change2CUI=y
    #AutoIt3Wrapper_Res_Description=Disk Free Space
    #AutoIt3Wrapper_Res_Fileversion=1.0.9.3
    #AutoIt3Wrapper_Res_LegalCopyright=2014  http://milesaheadsoftware.tk
    #AutoIt3Wrapper_Res_Language=1033
    #AutoIt3Wrapper_Res_Field=Productname|df
    #AutoIt3Wrapper_Res_Field=Productversion|1.093
    #AutoIt3Wrapper_Run_AU3Check=n
    #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
    #include <WinAPIEx.au3>
    Opt('MustDeclareVars', 1)
    Global $GB = 1024 * 1024 * 1024
    Global $MB = 1024 * 1024
    Global $KB = 1024
    Global $div, $whole, $frac, $unit, $result, $drive, $len
    
    If Not $CmdLine[0] Then
        $drive = StringLeft(@WorkingDir, 2)
        DisplaySpace()
        Exit
    ElseIf $CmdLine[1] = "/?" Then
        ShowHelp()
    Else
        For $x = 1 To $CmdLine[0]
            If StringLen($CmdLine[$x]) = 1 Then
                $drive = $CmdLine[$x] & ":"
            Else
                $drive = $CmdLine[$x]
            EndIf
            DisplaySpace()
        Next
    EndIf
    
    Func DisplaySpace()
        Local $Data = _WinAPI_GetDiskFreeSpaceEx($drive)
        If @error Then
            ConsoleWriteError("Error detecting free disk space on " & $drive & @CRLF)
            Return
        EndIf
        If $Data[2] >= $GB Then
            $div = $GB
            $unit = "GB"
        ElseIf $Data[2] >= $MB Then
            $div = $MB
            $unit = "MB"
        ElseIf $Data[2] >= $KB Then
            $div = $KB
            $unit = "KB"
        Else
            $div = 1
            $unit = "B "
        EndIf
        If $div = 1 Then
            $result = String($Data[2])
        Else
            $result = StringFormat("%.5f", $Data[2] / $div)
            If StringRight($result, 6) = ".00000" Then
                $result = StringLeft($result, StringInStr($result, ".") - 1)
            Else
                $result = StringLeft($result, StringInStr($result, ".") + 3)
            EndIf
        EndIf
        $result = StringFormat("%-9s", $result)
        $result &= $unit & " Free on "
        ConsoleWrite($result & $drive & @CRLF)
        If Not $CmdLine[0] Then
            ConsoleWrite(@TAB & "( df /? for help )" & @CRLF)
        EndIf
    EndFunc   ;==>DisplaySpace
    
    Func ShowHelp()
        Local $ver = FileGetVersion(@ScriptFullPath)
        If $ver = "0.0.0.0" Then
            $ver = ""
        EndIf
        ConsoleWrite(@CRLF & @ScriptName & " " & $ver & " Copyright " & @YEAR & " milesaheadsoftware.tk" & @CRLF)
        ConsoleWrite(@CRLF & "Usage: df [ C D \\Name\Share ]" & @CRLF & "free disk space in one of B KB MB GB" & @CRLF)
        ConsoleWrite(@CRLF & "( Truncated to 3 decimal places. )" & @CRLF & @CRLF)
        Exit
    EndFunc   ;==>ShowHelp
      My Computer


 
Page 2 of 2 FirstFirst 12

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 20:55.
Find Us