标题: [系统相关] 优化winsxs目录的BAT如何避免文件名或扩展名太长的错误 [打印本页]
作者: Nano 时间: 2011-12-2 12:26 标题: 优化winsxs目录的BAT如何避免文件名或扩展名太长的错误
本帖最后由 CrLf 于 2011-12-2 15:34 编辑
求达人修改优化winsxs目录的BAT
代码如下:- @echo off
- rem 获取windows版本
- set move_dir=%SystemRoot%\winsxs_del
- if not exist %move_dir%\nul md %move_dir%
- set winver=none
- FOR /F "eol=; tokens=4* delims=] " %%i in ('ver') do set winver=%%i
- if "%winver%" == "none" goto enover
- echo windows version is %winver%, ready to list winsxs dir.
- if not exist %SystemRoot%\winsxs\nul goto enosxs
-
- set ver_prefix=%winver:~0,-1%
- echo list winsxs finished! now ready to clear duplicated files
- echo dir /ad %SystemRoot%\winsxs\*_%ver_prefix%*
-
- if "%1" == "run-winsxs-generated" goto :lSkipGen
- rem 准备生成代码
- copy /y "%~f0" "%temp%\%~nx0" > nul
- echo rem genereted code here >> "%temp%\%~nx0"
- echo :ldcdStat1 >> "%temp%\%~nx0"
- echo set end4=%%arg:%ver_prefix%=%%>> "%temp%\%~nx0"
- echo goto ldcdStat2 >> "%temp%\%~nx0"
- echo :ldcdStat3 >> "%temp%\%~nx0"
- echo set end4a=%%arg:%winver%=%%>> "%temp%\%~nx0"
- echo goto ldcdStat4 >> "%temp%\%~nx0"
- rem notepad "%temp%\%~nx0"
- "%temp%\%~nx0" run-winsxs-generated
- goto :EOF
-
- :lSkipGen
- FOR /F "eol=; tokens=1-4 delims= " %%a in ('dir /ad %SystemRoot%\winsxs\*_%ver_prefix%*') do (
- if "%%c" == "<DIR>" call:fnDoClear %%d
- )
-
- echo clear OK!
- goto :EOF
-
- :enover
- echo could not get windows version, abort!
- goto :EOF
-
- :enosxs
- echo not found %SystemRoot%\winsxs! maybe no privilege or lower windows!
- echo only support windows XP and later!
- goto :EOF
-
- :fnDoClear
- rem arg: dir_name
- FOR /F "eol=; tokens=1-14 delims=_" %%g in ("%1") do call:fnDoClearDir %1 %%g %%h %%i %%j %%k %%l %%m %%n %%o %%p %%q %%r %%s %%t %%u %%v %%w %%x %%y %%z
- goto :EOF
-
- :fnDoClearDir
- rem arg: dir_name dir_parts
- set d_name=%1
- rem 检查参数是否匹配 %winver%, 先跳过前两个.同时准备组合新版本匹配名称,nv1存当前版本,nv2存当前的前一个版本
- set nv1=%2_%3_
- set nv2=%2_%3_
- :ldcdCycle
- if "%4" == "" goto :EOF
- rem 检查是否 ver_prefix 开头,如果是则继续检查是否winver,如果不是winver则表示目标存在
- set arg=%4
- rem set line=set end4=%%arg:%ver_prefix%=%%
- rem %line%
- goto ldcdStat1
- :ldcdStat2
- if "%arg%" == "%end4%" goto ldcdNext
- rem 检查是否 winver 开头
- rem set line=set end4a=%%arg:%winver%=%%
- rem %line%
- goto ldcdStat3
- :ldcdStat4
- if not "%arg%" == "%end4a%" goto :EOF
- rem 至此则为 ver_prefix 开头 且 不等于 winver 的目录名,检查最新版本是否存在,存在则可删除旧的
- set newfound=false
- for /d %%v in ("%SystemRoot%\winsxs\%nv1%%winver%.*_%5_*") do (
- if exist %%v\nul set newfound=true
- )
- if "%newfound%" == "true" call:fnDelDir %d_name%
-
- goto :EOF
- :ldcdNext
- set nv2=%nv1%
- set nv1=%nv2%%4_
- shift
- goto ldcdCycle
-
- :fnDelDir
- rem arg: dir
- echo del %SystemRoot%\winsxs\%1
- takeown /r /f "%SystemRoot%\winsxs\%1"
- cacls "%SystemRoot%\winsxs\%1" /t /e /g everyone:f
- move "%SystemRoot%\winsxs\%1" "%move_dir%\%1"
- goto :EOF
复制代码
问题:
有不少这样的错误:
处理的目录: C:\Windows\winsxs\msil_system.web.security..glesignon.resources_31bf
3856ad364e35_6.0.6001.18000_zh-cn_0a8560c79d0de78e
处理的文件: C:\Windows\winsxs\msil_system.web.security..glesignon.resources_31bf
3856ad364e35_6.0.6001.18000_zh-cn_0a8560c79d0de78e\System.Web.Security.SingleSig
nOn.Resources.dll
文件名或扩展名太长。
移动了 0 个目录。
作者: awk 时间: 2011-12-2 23:44
用dir /x命令获取短名,这样可以吗?
作者: Nano 时间: 2011-12-4 11:53
用dir /x命令获取短名,这样可以吗?
awk 发表于 2011-12-2 23:44
代码是网络上找的,本人不会命令呀,只是报下错。可否帮改下我可以帮测试,谢谢
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |