31 lines
992 B
Lua
31 lines
992 B
Lua
|
|
local ps =
|
|||
|
|
"Get-PSDrive -PSProvider FileSystem | " ..
|
|||
|
|
"Where-Object { $_.Used -ne $null -or $_.Free -ne $null } | " ..
|
|||
|
|
"ForEach-Object { '{0}:{1}' -f $_.Name, [math]::Round($_.Free/1GB,0) } | " ..
|
|||
|
|
"ForEach-Object { Write-Host -NoNewline ($_+' ') }"
|
|||
|
|
|
|||
|
|
local res = jarvis.system.exec(string.format(
|
|||
|
|
'powershell -NoProfile -Command "%s"', ps:gsub('"', '\\"')
|
|||
|
|
))
|
|||
|
|
|
|||
|
|
if not res.success then
|
|||
|
|
return jarvis.cmd.error("Не получилось.")
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
local out = (res.stdout or ""):gsub("^%s+", ""):gsub("%s+$", "")
|
|||
|
|
if out == "" then
|
|||
|
|
return jarvis.cmd.not_found("Дисков не нашёл.")
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
-- "C:120 D:300 E:50" → "C 120 ГБ, D 300 ГБ, ..."
|
|||
|
|
local parts = {}
|
|||
|
|
for letter, gb in out:gmatch("([A-Z]):(%d+)") do
|
|||
|
|
table.insert(parts, letter .. " " .. gb .. " гигабайт")
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
if #parts == 0 then
|
|||
|
|
return jarvis.cmd.error("Не понял ответ системы.")
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
return jarvis.cmd.ok("Свободно: " .. table.concat(parts, ", ") .. ".")
|