Windows Batch (cmd + vbs)Â¥´Â°Í Á» µµ¿ÍÁÖ¼¼¿ä

dateno1   
   Á¶È¸ 2085   Ãßõ 0    

 :DiskStatus
echo Letter / Label / Total Space / Used Space / Free Space / Filesystem
set "GB=1073741824"
for /f "skip=1 delims=" %%i in ('wmic logicaldisk get DeviceID^,FreeSpace^,Size^,VolumeName^,Filesystem') do (
  for /f "tokens=1-5" %%j in ("%%i") do call :Diskoutput %%j %%k %%l %%m %%n
)
:Diskoutput
if "%4"=="" (
  goto :eof
)
for /f "tokens=1-6" %%i in (
  'mshta vbscript:Execute("CreateObject(""Scripting.FileSystemObject"").GetStandardStream(1).Write(FormatNumber(%4/%GB%, 2) & "" "" & FormatNumber((%4-%3)/%GB%, 2) & "" "" & FormatNumber(%3/%GB%, 2) & "" "" & Round((%4-%2)*50/%4)):Close"^)'
) do (
  set "size=%%i"
  set "used=%%j"
  set "free=%%k"
  set /a "nUsed=%%l, nFree=50-%%l"
)
echo %1     / %5 / %size:~-10% GB / %used:~-10% GB / %free:~-10% GB / %2

보시는대로 wmic로 가져온 정보를 vbs로 용량 부분 GBi로 변환후 출력하는 함수입니다

호출해서 돌리면 이런식으로 찍힙니다


문젠 스샷에도 나오듯이 Label이나 획득한 용량의 문자열 길이에 따라서 레이아웃이 엉망으로 출력이 됩니다


출력 직전의 %2~5를 가공해서 일정 길이가 안 되면 모잘란만큼 공백을 추가해서 길이를 맞추면 될듯한데, batch로 문자열 못 다루어서 글 올려봅니다


출력되는 문자열 길이는 현제 존재하는 가장 큰 디스크인 16T까지를 상정해서 #####.##GB, Label경우는 전체 길이를 고려해서 10~15byte정도를 상한으로 잡고 레이아웃으로 잡고자 합니다

Letter / Label / Total Space / Used Space / Free Space / Filesystem

C:     /10글자/#####.##Gb /#####.##Gb /#####.##Gb /  NTFS

D:     /      D/    100.00Gb /      0.00Gb /    100.00Gb /  FAT332

이런식으로 모잘란 길이만큼 전방 공백으로 처리해서 일정하게 출력하면 됩니다


참고로 Powershell을 쓸 수 없는 환경에서 돌릴꺼라 Powershell로는 짤 수 없습니다 (외부 바이너리 추가가 필요하면 써도 상관없지만, 상용 사용이 허가되어있어야 합니다)



맨날 삽질만 하고 삽니다

http://www.2cpu.co.kr/hardware_2014/44147
컴 케이스 작다고 불타거나 하지 않아요

ªÀº±Û Àϼö·Ï ½ÅÁßÇÏ°Ô.
¹«¾Æ 2021-09
¸ÚÁøµ¥¿ä..
Á¦ ÄÄÇ»ÅÍ¿¡¼­ Çѹø µ¹·Á º¼°Ô¿ä...¤¾
     
dateno1 2021-09
cmd·Î ÀúÀåÈÄ Á© À§ÀÇ :DiskStatus¸¦ »èÁ¦ÇÏ°í Á© ¹Ø¿¡ Pause Ãß°¡ÇÏ¸é ¾î¶²½ÄÀÎÁö ³ª¿Í¿ä
¹«¾Æ 2021-09
¿¹¸¦ µé¾î
½ºÅ©¸³Æ® ³»¿¡
FormatNumber(%3/%GB%, 2)
·Î µÈ ºÎºÐÀ»
Right("        " & FormatNumber(%3/%GB%, 2), 10)
¿ä·± ½ÄÀ¸·Î ¾Õ¿¡ ½ºÆäÀ̽º¸¦ Àû´çÈ÷ ³ÖÀº ´ÙÀ½¿¡ Right ÇÔ¼ö·Î ¿øÇÏ´Â ±æÀÌ(À§¿¡¼± 10Ä­À̶ó Çß°í) ¸¸Å­ Àß¶ó¼­ ¾²¸é...
Right(String(10," ") & FormatNumber(%3/%GB%, 2), 10)  ¿ä·¸°Ô Çß´õ´Ï ¹º°¡ ¿¡·¯°¡ ³ª¼­ À߾ȵdz׿ä. vbs´Â ¾È½áºÁ¼­...
     
dateno1 2021-09
Àúµµ vbs´Â 1~20³âÂë¿¡³ª ´Ù·ç´Ù°¡ ¾Æ¿¡ ¹ö·Á³ö¼­ Àß ±â¾ïÀÌ ¾È ³ª¿ä
¹«¾Æ 2021-09
¸Ç ¾Æ·¡ÂÊ Äڵ带 ´ÙÀ½°ú °°ÀÌ °íÄ¡´Ï µÇ³×¿ä.

) do (
  set "label=                  %5"
  set "size=                  %%i"
  set "used=                  %%j"
  set "free=                  %%k"
  set /a "nUsed=%%l, nFree=50-%%l"
)
echo %1    / %label:~-10% / %size:~-10% GB / %used:~-10% GB / %free:~-10% GB / %2

À§ÂÊ¿¡ Ä÷³¸íÀº ¾Ë¾Æ¼­ ¸ÂÃß½Ã¸é µÇ°í..


     
dateno1 2021-09
ÄÀ;

½ÇÄÆ ÄÚµå Â¥´Ù°¡ Áö±Ý µé¾î¿Íº¸´Ï Á¤´äÀÌ Àֳ׿ä (°¨»çÇÕ´Ï´Ù)

echo Letter /          Label/ Total Space /  Used Space /  Free Space / Filesystem
set "GB=1073741824"
for /f "skip=1 delims=" %%i in ('wmic logicaldisk get DeviceID^,FreeSpace^,Size^,VolumeName^,Filesystem') do (
  for /f "tokens=1-5" %%j in ("%%i") do call :Diskoutput %%j %%k %%l %%m %%n
)
:Diskoutput
if "%4"=="" (
  goto :eof
)
for /f "tokens=1-6" %%i in (
  'mshta vbscript:Execute("CreateObject(""Scripting.FileSystemObject"").GetStandardStream(1).Write(FormatNumber(%4/%GB%, 2) & "" "" & FormatNumber((%4-%3)/%GB%, 2) & "" "" & FormatNumber(%3/%GB%, 2) & "" "" & Round((%4-%2)*50/%4)):Close"^)'
) do (
  set "size=%%i"
  set "used=%%j"
  set "free=%%k"
  set /a "nUsed=%%l, nFree=50-%%l"
)

set varLetter=%1
rem -------------------------------------------------------------------
set varLabel=%5
set PadLabel1=%varLabel:~%
call :padLabel
set varLabel=%PadLabel2:~%

set varTotalSpace=%size:~-10%
set PadTotalSpace1=%varTotalSpace:~%
call :padTotalSpace
set varTotalSpace=%PadTotalSpace2:~%

set varUsedSpace=%used:~-10%
set PadUsedSpace1=%varUsedSpace:~%
call :padUsedSpace
set varUsedSpace=%PadUsedSpace2:~%

set varFreeSpace=%free:~-10%
set PadFreeSpace1=%varFreeSpace:~%
call :padFreeSpace
set varFreeSpace=%PadFreeSpace2:~%

set varFilesystem=%2
set PadFilesystem1=%varFilesystem:~%
call :padFilesystem
set varFilesystem=%PadFilesystem2:~%

goto :EOF
rem -------------------------------------------------------------------
:padLabel
set PadLabel1=%PadLabel1:~% **********
set PadLabel1=%PadLabel1:~0,14%
for /f "tokens=1,2" %%a in ("%PadLabel1%") do set PadLabel1=%%b%%a

set PadLabel1=%PadLabel1:~%
set PadLabel1=%PadLabel1: =`%
set PadLabel2=
set /a counter=-1

:Labelnxtchar
set /a counter+=1
call :EXEC set padchar=%%PadLabel1:~%counter%,1%%%
if not defined padchar goto :eof
if [%padchar%] EQU [*] set padchar=
set PadLabel2=%PadLabel2%%padchar%
goto :Labelnxtchar
rem -------------------------------------------------------------------
:padTotalSpace
set PadTotalSpace1=%PadTotalSpace1:~% **********
set PadTotalSpace1=%PadTotalSpace1:~0,9%
for /f "tokens=1,2" %%a in ("%PadTotalSpace1%") do set TotalSpace1=%%b%%a

set PadTotalSpace1=%PadTotalSpace1:~%
set PadTotalSpace1=%PadTotalSpace1: =%
set PadTotalSpace2=
set /a counter=-1

:TotalSpacenxtchar
set /a counter+=1
call :EXEC set padchar=%%PadTotalSpace1:~%counter%,1%%%
if not defined padchar goto :eof
if [%padchar%] EQU [*] set padchar=
set PadTotalSpace2=%padchar%%PadTotalSpace2%
goto :TotalSpacenxtchar
rem -------------------------------------------------------------------
:padUsedSpace
set PadUsedSpace1=%PadUsedSpace1:~% **********
set PadUsedSpace1=%PadUsedSpace1:~0,9%
for /f "tokens=1,2" %%a in ("%PadUsedSpace1%") do set UsedSpace1=%%b%%a

set PadUsedSpace1=%PadUsedSpace1:~%
set PadUsedSpace1=%PadUsedSpace1: =%
set PadUsedSpace2=
set /a counter=-1

:UsedSpacenxtchar
set /a counter+=1
call :EXEC set padchar=%%PadUsedSpace1:~%counter%,1%%%
if not defined padchar goto :eof
if [%padchar%] EQU [*] set padchar=
set PadUsedSpace2=%padchar%%PadUsedSpace2%
goto :UsedSpacenxtchar
rem -------------------------------------------------------------------
:padFreeSpace
set PadFreeSpace1=%PadFreeSpace1:~% **********
set PadFreeSpace1=%PadFreeSpace1:~0,9%
for /f "tokens=1,2" %%a in ("%PadFreeSpace1%") do set FreeSpace1=%%b%%a

set PadFreeSpace1=%PadFreeSpace1:~%
set PadFreeSpace1=%PadFreeSpace1: =%
set PadFreeSpace2=
set /a counter=-1

:FreeSpacenxtchar
set /a counter+=1
call :EXEC set padchar=%%PadFreeSpace1:~%counter%,1%%%
if not defined padchar goto :eof
if [%padchar%] EQU [*] set padchar=
set PadFreeSpace2=%padchar%%PadFreeSpace2%
goto :FreeSpacenxtchar
rem -------------------------------------------------------------------
:padFilesystem
set padFilesystem1=%padFilesystem1:~% **********
set padFilesystem1=%padFilesystem1:~0,11%
for /f "tokens=1,2" %%a in ("%padFilesystem1%") do set padFilesystem1=%%b%%a

set padFilesystem1=%padFilesystem1:~%
set padFilesystem1=%padFilesystem1: =`%
set padFilesystem2=
set /a counter=-1

:Filesystemnxtchar
set /a counter+=1
call :EXEC set padchar=%%PadFilesystem1:~%counter%,1%%%
if not defined padchar goto :done
if [%padchar%] EQU [*] set padchar=
set PadFilesystem2=%PadFilesystem2%%padchar%
goto :Filesystemnxtchar
rem -------------------------------------------------------------------
:done
echo %varLetter%    / %PadLabel2% / %PadTotalSpace2% GB / %PadUsedSpace2% GB / %PadFreeSpace2% GB / %PadFilesystem2%

goto :EOF

:EXEC
%*
goto :EOF

ÀÌ·± ¾²·¹±â Äڵ带 ÀÛ¼ºÈÄ µð¹ö±× ÇÏ°í ÀÖ¾ú½À´Ï´Ù (...) (ÀÛµ¿Àº Çϴµ¥, ¿ë·® ºÎºÐÀÌ Å׶ó´ÜÀ§°¡ µÇ¾î¼­ ³Ê¹« ±æ¸é ¹®Á¦µÇ´Â°Å¶û LabelÀÌ ¾ø´Â°æ¿ì ~·Î ³ª¿À´Â°Í °íÄ¥·Á°í »ðÁúÁßÀ̾úÀ½)

¿ª½Ã ÇÁ·Î±×·¡¹ÖÀº ¾Æ¹«¸® °£´ÜÇÑ°Å¶óµµ ¾Æ´Â°Ô ÈûÀ̱º¿ä (ÄÚµå ºÐ·®µµ ¹®Á¦Áö¸¸, ·çÇÁ¸¦ ³Ñ ¸¹ÀÌ ½á¼­ ó¸® ¼º´Éµµ ³ª»Ý)
     
dateno1 2021-09
ÃÖÁ¾ÀûÀ¸·Î
@echo off

echo ^|------^|---------------^|-------------^|-------------^|-------------^|----------^|
echo ^|Letter^|          Label^| Total Space ^|  Used Space ^|  Free Space ^|Filesystem^|
echo ^|------^|---------------^|-------------^|-------------^|-------------^|----------^|
set "GB=1073741824"
for /f "skip=1 delims=" %%i in ('wmic logicaldisk get DeviceID^,FreeSpace^,Size^,VolumeName^,Filesystem') do (
  for /f "tokens=1-5" %%j in ("%%i") do call :Diskoutput %%j %%k %%l %%m %%n
)
:Diskoutput
if "%4"=="" (
  goto :eof
)
for /f "tokens=1-6" %%i in (
  'mshta vbscript:Execute("CreateObject(""Scripting.FileSystemObject"").GetStandardStream(1).Write(FormatNumber(%4/%GB%, 2) & "" "" & FormatNumber((%4-%3)/%GB%, 2) & "" "" & FormatNumber(%3/%GB%, 2) & "" "" & Round((%4-%2)*50/%4)):Close"^)'
) do (
  set "label=                  %5"
  set "size=                  %%i"
  set "used=                  %%j"
  set "free=                  %%k"
  set "FileSystem=            %2"
  set /a "nUsed=%%l, nFree=50-%%l"
)
echo ^|%1    ^|%label:~-14% ^|%size:~-9% GB ^|%used:~-9% GB ^|%free:~-9% GB ^|  %Filesystem:~-6% ^|
echo ^|------^|---------------^|-------------^|-------------^|-------------^|----------^|
ÀÌ·¸°Ô ·¹À̾ƿô Á¶ÀýµÇ¾ú½À´Ï´Ù


QnA
Á¦¸ñPage 5151/5680
2015-12   1482043   ¹é¸Þ°¡
2014-05   4945359   Á¤ÀºÁØ1
2022-11   2108   Àª¶ó¸ä
2023-02   2108   °­Çѱ¸
2020-01   2108   Ȧ¸¯0o0
2018-12   2108   »ßµ¹À̽½ÇÄÀÌ
2022-08   2108   ¼º³É¾È»ç¿ä
2023-08   2108   ¸·³»ÀÇÇÏ·ç
2022-06   2108   ciscocom
2023-01   2108   ȸ¿ø
2021-06   2108   ÀüÁ÷P¿¬±¸¿ø
2021-08   2108   ¹ÚÇö¹®
2021-09   2107   ¼ÛÁÖȯ
02-02   2107   ½ÅÀº¿Ö
2023-09   2107   kinyou
2019-11   2107   ½Ã°ñ³ëÀÎ
02-25   2107   ºý½Ã´Ù
2020-11   2107   ºñºñBB
2022-05   2107   ±èÁ¦¿¬
2023-04   2107   ÇÇÄ«Ãß
2021-09   2106   ¸·¿ï¾ú¾î¿ä
2021-06   2106   Çعо²