Thank you
![Smile :)](./images/smilies/icon_e_smile.gif)
This seems to be incorrect for x64. hThread would be at offset A_PtrSize.SKAN wrote:, hThread := NumGet(PI,4)
Yes.
Code: Select all
MsgBox % RunCMD("powershell Get-Host | Select-Object Version")
Code: Select all
MsgBox % RunCMD("powershell Get-Content 'license.txt' -Tail 13", A_AhkPath . "\..\")
Code: Select all
MsgBox % RunCMD("powershell (New-TemporaryFile).fullname")
Code: Select all
MsgBox % RunCMD("powershell Get-Random -Minimum 100 -Maximum 1000")
MsgBox % RunCMD("powershell Get-Random -InputObject 'John','Sean','Naomi','Maura','Neula'")
Code: Select all
MsgBox % RunCMD("powershell Invoke-RestMethod -Uri http://expandurl.com/api/v1/?url=ahkscript.org")
Code: Select all
MsgBox % RunCMD("powershell [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12;"
. "Invoke-RestMethod -Uri 'https://autohotkey.com/download/1.1/version.txt'")
Code: Select all
MsgBox % RunCMD("powershell Add-Type -AssemblyName System.Web;"
. "[System.Web.HttpUtility]::UrlEncode('https://www.autohotkey.com/')")
MsgBox % RunCMD("powershell Add-Type -AssemblyName System.Web;"
. "[System.Web.HttpUtility]::UrlDecode('https%3a%2f%2fwww.autohotkey.com%2f')")
Code: Select all
MsgBox % RunCMD("powershell (gci '" A_DeskTop "' -Recurse | Measure-Object -Property Length -sum).sum")
Code: Select all
MsgBox % RunCMD("powershell (Get-FileHash '" A_AhkPath "' -Algorithm SHA256).hash")
Thanks for the feedback.burque505 wrote:All examples work for me on Win7.
Code: Select all
---------------------------
Version: 5.1.14409.1018
burque505 wrote:Version: 5.1.14409.1018
Code: Select all
FolderSize(folder) { ;gwarble 2020 - any faster method to get folder size?
Loop, Parse, % RunCMD("robocopy /l /nfl /ndl " folder " . /r:0 /w:0 /e /bytes"), `n, `r
If InStr(A_LoopField,"Bytes :") ;thanks SKAN for RunCMD()
For each, z in StrSplit(RegExReplace(A_LoopField, "\s+", " "), " ")
If (A_Index = 4) ;probably much better ways to parse result
Return z
}
Thanks for the feedback
Yes. Powershell is too slow. Nice func.. Thanks for sharing.powershell sure adds a lot of bloat, even an empty folder is 10 times slower than robocopy...
Code: Select all
FolderSize(P*) { ; modified by SKAN @ autohotkey.com/boards/viewtopic.php?p=341757#p341757
If (P.Count()=2) ; Original by gwarble @ autohotkey.com/boards/viewtopic.php?p=341577#p341577
Return InStr(P[1],"Bytes :") ? StrSplit(Trim(SubStr(P[1], 11, 20))," ").1 : ""
Return RunCMD("robocopy /l /nfl /ndl " P[1] " . /r:0 /w:0 /e /bytes",,, A_ThisFunc)
}
Code: Select all
Loop, Parse, _, `n, `r
{
If InStr(A_LoopField,"Dirs :")
For each, z in StrSplit(RegExReplace(A_LoopField, "\s+", " "), " ")
If (A_Index = 4)
Dirs := z - 1 ;just for consistency with explorer properties results
If InStr(A_LoopField,"Files :")
For each, z in StrSplit(RegExReplace(A_LoopField, "\s+", " "), " ")
If (A_Index = 4)
Files := z
If InStr(A_LoopField,"Bytes :")
For each, z in StrSplit(RegExReplace(A_LoopField, "\s+", " "), " ")
If (A_Index = 4)
Bytes := z
}
MsgBox, % " Dirs: " Dirs "`n Files: " Files "`n Size: " FormatBytes(Bytes)
Yes. Definitely an advantage.gwarble wrote:you also get more data for free, like the number of folders and number of files
Yes. That gives me a plan.gwarble wrote:yes (and there are a ton of useful options for copying as well, just be careful if you remove the /L it will actually do stuff not just report info)
Neat. BTW, \ also seems to work.gwarble wrote: Edit: yes the dot is the unused destination, was the shortest I could come up with... the example I learned from used \\localhost\c$\nul for some reason I couldn't figure out, and c: might not always exist so I didn't like it
I only said That gives me a plan.TheArkive wrote:I'm dying to know ... how did you get to actually capture a progress bar on the command line ... in that tiny little function? ...
Code: Select all
#NoEnv
#SingleInstance, Force
MsgBox % "ExitCode = " . RoboCopyPro("""C:\Program Files"" *.txt ""D:\Text_"" /IS /S")
Return
RoboCopyPro(P*) {
Static TOTAL:=0, FTOTAL:=0, WRITE:=0, FWRITE:=0, VAR, N:=VarSetCapacity(VAR,16,0)
Static SPATH := Format("{:260}",""), F:=0, PROG:=0, LINE:="", TEXT:=""
Global A_Args
If ( TOTAL )
{
If ! WinExist("RoboCopy Progress ahk_class AutoHotkey2")
Return % ("", A_Args.RunCMD.PID:=0)
If ! (F:=StrSplit(P[1], A_Tab, A_Space)).4
Return
WRITE += F[4], Prog := Round((WRITE/TOTAL)*100)
DllCall("shlwapi.dll\PathCompactPathEx", "Str",SPATH, "Str",F[5], "Int",60 )
FWRITE := DllCall("Shlwapi\StrFormatByteSize64A", "Int64",WRITE, "Str",VAR, "Int",16, "AStr")
Progress, 4:%Prog%, %FWRITE% out of %FTOTAL% `t`t %PROG%`%, %sPath%, RoboCopy Progress, Segoe UI
Sleep 100 ; RoboCopy is too fast! Slowing it down to reduce text update flicker!
Return
}
Progress, 4: M2 C00 zX25 ZY15 ZH20 W480 WM400 WS400 FM10 FS10, 0`%, Calculating size...
, RoboCopy Progress, Segoe UI
TEXT := RunCMD("ROBOCOPY " . P[1] . " /R:0 /W:0 /BYTES /NFL /NDL /NJH /L")
Loop, Parse, TEXT, `n, `r
If InStr(LINE:=A_LoopField, "Bytes :")
Break
If ! (TOTAL := StrSplit(Trim(SubStr(LINE, 11, 20))," ").1)
Return
FTOTAL := DllCall("Shlwapi\StrFormatByteSize64A", "Int64",TOTAL, "Str",VAR, "Int",16, "AStr")
Progress, 4:, %FTOTAL%, Calculating size...`n, RoboCopy Progress, Segoe UI
RunCMD("ROBOCOPY " . P[1] . " /R:0 /W:0 /BYTES /NDL /NJH /NJS",,,A_ThisFunc)
TOTAL := 0
VAR := ErrorLevel
Sleep 1000
Progress, 4:Off
Return VAR
}
Thank youbeautiful
True. I'm fascinated by the mirror facility robocopy offers.while i always prefer native ahk vs using an external program or library, sometimes results are more important and robocopy delivers
I think I might have tried it once long time before... I will put it to good use this time.its been around since the NT days to so i like to think its as robust (failsafe?) as the name suggests
Return to “Scripts and Functions (v1)”
Users browsing this forum: No registered users and 233 guests