WinSxS文件夾是冗余文件存放的位置,通常位於C:\Windows目錄路徑下,該文件夾下所存儲的主要是系統備份、更新補丁備份,WinSxS文件夾會隨著時間的推遠,而逐漸成為系統盤中最大的文件夾。
對於普通用戶來說,最關心的是WinSxS文件夾為何持續變大?實際上,WinSxS文件夾具體功能為組件存儲,裡面存儲了Windows重要組件功能,例如大家熟悉的C:\Windows\system32目錄。
在WinSxS文件夾中,主要由三部分組成:
1、與Windows共享;
2、備份和已禁用的功能;
3、緩存和臨時數據。
而WinSxS文件夾是可以刪除的,TA自身與C:\Windows\system32目錄創建了硬鏈接,因此,我們很難在資源管理器直接查看實際大小也需要一定的權限才能刪除該文件夾,參考下圖:
那我們如何查看這個文件夾實際大小呢?
1、在搜索框中輸入:cmd,然後右擊以管理員身份運行;
2、在打開的命令提示符中輸入如下查詢命令:Dism.exe /Online /Cleanup-Image /AnalyzeComponentStore,查詢當前WinSxS文件夾實際大小;
從以上圖片中不難看出,WinSxS文件夾實際容量低於Windows資源管理器的數據顯示。
如何刪除WinSxS文件?
將下方代碼復制到文本文檔中保存,之後修改.txt後綴為.bat雙擊打開,跟隨命令提示進行回車,等待命令執行完畢即可(這個過程中如果出現多個“拒絕訪問”字眼,則證明用戶賬戶的權限不夠高導致的)。
代碼如下:
@echo off
set mxms=a
if not "!mxms!" == "a" set mxms=&&%comspec% /V:ON /C %0 %* && goto :EOF
set mxms=
rem 算法描述:
rem windows的winsxs目錄中文件夾的格式都是:"類型_名字_庫id_版本號_語言_簽名"
rem 檢查所有的文件夾,如果發現有版本不同的文件存在,則刪除所有舊版本的文件夾
rem 需要注意:名字部分可能也會包含多個下劃線
rem 創建目錄
set startT=%TIME%
set move_dir=%SystemRoot%\winsxs_del
if not exist %move_dir%\nul md %move_dir%
set log=%temp%\winsxs-clear.log
pushd "%SystemRoot%\winsxs"
echo ===================== start TE% %TIME% ============================ >> "%log%"
rem 遍歷winsxs文件夾的所有目錄
FOR /F "eol=; tokens=1-4 delims= " %%a in ('dir /ad /o-n %SystemRoot%\winsxs\*.*') do (
if "%%c" == "<DIR>" if exist "%SystemRoot%\winsxs\%%d" call:fnDoClear %%d
)
echo ===================== OK! TE% %TIME% ============================ >> "%log%"
echo clear OK!
echo from %startT% to %TIME%. Check your '%move_dir%' please.
echo view log from %log%
set startT=
set move_dir=
popd
goto :EOF
:fnDoClear
rem arg: dir_name
rem 分解目錄名
FOR /F "eol=; tokens=1-14 delims=_" %%g in ("%1") do (
call:fnSplitName %1
if not "%f_type%" == "" call:fnDoClearDir %1 !f_type! !f_name! !f_id! !f_rev! !f_lang! !f_sign!
)
goto :EOF
:fnSplitName
rem arg: dir_name
rem return f_xxx vars
set f_type=
set f_name=
set f_id=
set f_rev=
set f_lang=
set f_sign=
FOR /F "eol=; tokens=1-14 delims=_" %%g in ("%1") do (
if "%%m" == "" (
set f_type=%%g
set f_name=%%h
set f_id=%%i
set f_rev=%%j
set f_lang=%%k
set f_sign=%%l
) else ( if "%%n" == "" (
set f_type=%%g
set f_name=%%h_%%i
set f_id=%%j
set f_rev=%%k
set f_lang=%%l
set f_sign=%%m
) else ( if "%%o" == "" (
set f_type=%%g
set f_name=%%h_%%i_%%j
set f_id=%%k
set f_rev=%%l
set f_lang=%%m
set f_sign=%%n
) else ( if "%%p" == "" (
set f_type=%%g
set f_name=%%h_%%i_%%j_%%k
set f_id=%%l
set f_rev=%%m
set f_lang=%%n
set f_sign=%%o
) else ( if "%%q" == "" (
set f_type=%%g
set f_name=%%h_%%i_%%j_%%k_%%l
set f_id=%%m
set f_rev=%%n
set f_lang=%%o
set f_sign=%%p
) else ( if "%%r" == "" (
set f_type=%%g
set f_name=%%h_%%i_%%j_%%k_%%l_%%m
set f_id=%%n
set f_rev=%%o
set f_lang=%%p
set f_sign=%%q
) else ( if "%%s" == "" (
set f_type=%%g
set f_name=%%h_%%i_%%j_%%k_%%l_%%m_%%n
set f_id=%%o
set f_rev=%%p
set f_lang=%%q
set f_sign=%%r
) else ( if "%%t" == "" (
set f_type=%%g
set f_name=%%h_%%i_%%j_%%k_%%l_%%m_%%n_%%o
set f_id=%%p
set f_rev=%%q
set f_lang=%%r
set f_sign=%%s
) else ( if "%%u" == "" (
set f_type=%%g
set f_name=%%h_%%i_%%j_%%k_%%l_%%m_%%n_%%o_%%p
set f_id=%%q
set f_rev=%%r
set f_lang=%%s
set f_sign=%%t
) else ( if "%%v" == "" (
set f_type=%%g
set f_name=%%h_%%i_%%j_%%k_%%l_%%m_%%n_%%o_%%p_%%q
set f_id=%%r
set f_rev=%%s
set f_lang=%%t
set f_sign=%%u
) else (
echo ERROR: can not split "%1"
))))))))))
)
goto :EOF
:fnDoClearDir
rem arg: dir_name type namespace id revision lang sign
rem 找到最新版本的目錄名
call:fnStdVer %5
set curorgver=%5
set curver=%R_STDVER%
set cursign=%7
set R_STDVER=
set newver=
set neworgver=
set newsign=
FOR /F "eol=; tokens=1-4 delims= " %%a in ('dir /ad /o-n %2_%3_%4_*_%6_*') do (
if "%%c" == "<DIR>" (
call:fnSplitName %%d
if not "%f_type%" == "" call:fnCompVer "!newver!" !f_rev! !f_sign!
)
)
rem 如果沒找到則返回
if "%newver%" == "" goto :EOF
rem 如果找到,則將所有舊版本的清除
echo keep %2_%3_%4 %6 version %neworgver%
echo keep %2_%3_%4 %6 version %neworgver% >> "%log%"
FOR /F "eol=; tokens=1-4 delims= " %%a in ('dir /ad /o-n %2_%3_%4_*_%6_*') do (
if "%%c" == "<DIR>" (
call:fnSplitName %%d
if not "!f_type!" == "" (
if not "!neworgver!" == "!f_rev!" if not "!newsign!" == "!f_sign!" (
echo ... clear %2_%3_%4 %6 version !f_rev!
echo ... clear %2_%3_%4 %6 version !f_rev! >> "%log%"
call:fnDelDir "%%d"
)
)
)
)
goto :EOF
:fnCompVer
rem oldver newver newsign
rem result set var newver
rem 分解ver的每一個部分,左側填充0之後再比較
set V1=%~1
call:fnStdVer %2
set V2=%R_STDVER%
set R_STDVER=
if "%~1" == "" set neworgver=%2&&set newver=%V2%&&set newsign=%3&& goto :EOF
if /I "%V1%" LSS "%V2%" set neworgver=%2&&set newver=%V2%&&set newsign=%3&& goto :EOF
goto :EOF
:fnStdVer
rem arg: ver
FOR /F "eol=; tokens=1-10 delims=." %%v in ("%1") do call:fnStdVerImpl %%v %%w %%x %%y %%z
goto :EOF
:fnStdVerImpl
rem major, minor, revision, build
rem result set in R_STDVER
set svi_1=0000000000%1
set svi_2=0000000000%2
set svi_3=0000000000%3
set svi_4=0000000000%4
set svi_5=0000000000%5
set svi_6=0000000000%6
set R_STDVER=%svi_1:~-10%.%svi_2:~-10%.%svi_3:~-10%.%svi_4:~-10%.%svi_5:~-10%.%svi_6:~-10%
goto :EOF
:fnDelDir
rem arg: dir
echo deleting %SystemRoot%\winsxs\%~1 >> "%log%"
echo --- takeown >> "%log%"
takeown /r /f "%SystemRoot%\winsxs\%~1" >> "%log%"
echo --- takeown = %ERRORLEVEL% >> "%log%"
echo --- cacls >> "%log%"
cacls "%SystemRoot%\winsxs\%~1" /t /e /g everyone:f >> "%log%"
echo --- cacls = %ERRORLEVEL% >> "%log%"
echo --- move >> "%log%"
move "%SystemRoot%\winsxs\%~1" "%move_dir%\%~1" >> "%log%"
echo --- move = %ERRORLEVEL% >> "%log%"
goto :EOF
冗余文件相對正常文件夾刪除比較麻煩,如果用戶對冗余文件有興趣,不妨研究一下。