
폴더와 그 하위 폴더(디렉터리와 그 하위 디렉터리)를 어떻게 탐색하고 해당 폴더에서 발생하는 모든 확장자에 대해 총 몇 개의 특정 확장자의 파일이 있는지 나열할 수 있습니까?
이것과 비슷한 것,
folders 48 total
.jpg 2842 total
.gif 142 total
.CR2 2842 total
dir/s
위의 합계는 일부 폴더의 모든 파일 및 하위 폴더를 나열하는 합계와 동일해야 합니다 .
답변1
명령줄이 필요하지 않으면 WinDirStat를 사용할 수 있습니다.http://windirstat.info/download.html
답변2
다음 코드 조각이 도움이 될 수 있습니다.
@ECHO OFF >NUL
SETLOCAL EnableExtensions
rem EnableDelayedExpansion
rem next line: clear/delete all `_filesTotal` environment variables
for /F "delims==" %%G in ('set _filesTotal 2^>NUL') do set "%%G="
rem next line: initialize `_foldersTotal` environment variable
set "_foldersTotal=0"
pushd "folder where count"
for /F "delims=" %%G in ('dir /B /S /A') do (
if exist "%%~G\" (
rem folder %%G
set /A "_foldersTotal+=1"
) else (
rem file %%G
if "%%~xG"=="" (set /A "_filesTotal.+=1") else (set /A "_filesTotal%%~xG+=1")
)
)
rem next two lines: display raw results
echo %CD%
set _foldersTotal
set _filesTotal
popd
자원(필수 읽기):
- (명령 참조)Windows CMD 명령줄의 AZ 인덱스
- (추가 특징)Windows CMD 셸 명령줄 구문
- (
%~G
등 특별 페이지)명령줄 인수(Parameters) - (
>>
,2>NUL
등 특별 페이지)리디렉션
답변3
귀하의 질문에 Powershell 접근 방식을 고려해 보시기 바랍니다. 출력을 정렬하는 기능이 있어 코드 줄이 약간 줄어듭니다.
$foldercount = 0
$hash = @{}
Get-ChildItem -Path "C:\Code Samples" -Recurse | ForEach-Object {
if ($_.Attributes -eq 'Directory')
{
++$foldercount
}
else
{
if ($hash.ContainsKey($_.Extension))
{ $count = $hash.Get_Item($_.Extension); ++$count; $hash.Set_Item($_.Extension, $count) }
else
{ $hash.Add($_.Extension, 1) }
}
}
Write-Host $foldercount folders
$hash.GetEnumerator() | Sort-Object Value -descending
그리고 내 샘플 폴더에 대해 이 출력을 생성합니다...
90 folders
Name Value
---- -----
.tlog 186
.h 72
.obj 56
.cpp 54
.pdb 26
.manifest 24
.res 23
.rc 22
.log 15
.lastbuildstate 12
.ipch 12
.ico 12
.exe 12
.idb 12
.vcxproj 11
.ilk 11
.user 11
.sdf 11
.zip 11
.filters 11
.sln 11
.pch 11
.txt 8
.gif 8
.rc2 8
.aps 8
.bmp 7
.dsw 6
.dsp 6
.png 5
.css 5
.html 4
.old 4
.XML 4
.vcproj 4
.xslt 4
.exp 3
.dll 3
.lib 3
.clw 2
.def 2
.opt 2
.ncb 2
.plg 2
.recipe 2
.rtf 1
.jpg 1
.h original 1
.bat 1
.js 1
.cpp original 1
.DPbcd 1
답변4
이것은 매우 간단하고 효율적인 접근 방식입니다.
find . -type f | sed -n 's/..*\.//p' | sort | uniq -c