Windows 7 Forums

Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: Command Line - Help

12 Sep 2014   #11
MilesAhead

Windows 7 32 bit
 
 

Quote:
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 System SpecsSystem Spec
.
12 Sep 2014   #12
MilesAhead

Windows 7 32 bit
 
 

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 System SpecsSystem Spec
Reply

 Command Line - Help




Thread Tools Search this Thread
Search this Thread:

Advanced Search




Similar help and support threads
Thread Forum
Command line - Some questions
I've created a batch file for zipping selected items in a folder. (The file is placed in 'Send to'). If I use the following code: for %%* in (.) do set CurrentFolder=%%~n* "C:\Program Files\WinRar\WinRar" a -afzip "%CurrentFolder%.xpi" The file name is that of the current folder...
General Discussion
What is wrong with this command line?
Help please I am pulling my hair out. I use a desktop shortcut to run an application called get_iplayer.cmd located in the directory c:\program files\get_iplayer The line in the Target of the shortcut properties therefore reads: C:\Windows\System32\cmd.exe /k "c:\program...
General Discussion
How can I set this via command-line or registry?
How can I set this via command-line or registry? I need a way to automatically launch "Explorer c:\folder\myfolder" with a view appropriate for long filenames on any Windows Vista/Win7 PC.
Customization
Gpedit via command line
how can I enable disable a policy using gpedit! Not via the GUI, you go do some clicks and enable. But I want to execute one shot command which will say disable AutoRun. I have searched exenstively, no results. I kind need this for my automation stuff. Thanks, Akshay
Performance & Maintenance
How to run a command line utility?
Hi, I am trying to run a command line prompt utility from Microsoft on windows 7. Sure I am doing something wrong, after I click the downloaded .exe file the command prompt pops up briefly then disappears. Can someone explain the basics of running a command line utility on win7? Thanks! ...
General Discussion
Command Line
Is there a cmd.exe /switch for “run as administrator” ? Thanks-
General Discussion


Our Sites

Site Links

About Us

Find 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 13:33.

Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App