答案 0 :(得分:0)
Windows 10 64位
使用compact和cmd for loop设置文件夹和/或文件的compress属性。
为每个名称以holder
结尾的文件夹设置compress属性。压缩文件夹名称以holder
结尾的每个文件夹中的非系统文件或隐藏文件。如果COMPACT遇到错误,则停止。
CMD:
FOR /f "tokens=*" %g in ('DIR /ad /b /s "*holder"') do COMPACT /c "%g"
FOR /f "tokens=*" %g in ('DIR /ad /b /s "*holder"') do FOR /f "tokens=*" %h in ('DIR /a-d /b "%g"') do COMPACT /c "%g\%h"
rem un-set un-compress
FOR /f "tokens=*" %g in ('DIR /ad /b /s "*holder"') do COMPACT /u "%g"
FOR /f "tokens=*" %g in ('DIR /ad /b /s "*holder"') do FOR /f "tokens=*" %h in ('DIR /a-d /b "%g"') do COMPACT /u "%g\%h"
脚本:
FOR /f "tokens=*" %%g in ('DIR /ad /b /s "*holder"') do ECHO COMPACT /c "%%g"
FOR /f "tokens=*" %%g in ('DIR /ad /b /s "*holder"') do FOR /f "tokens=*" %%h in ('DIR /a-d /b "%%g"') do ECHO COMPACT /c "%%g\%%h"
rem un-set un-compress
FOR /f "tokens=*" %%g in ('DIR /ad /b /s "*holder"') do ECHO COMPACT /u "%%g"
FOR /f "tokens=*" %%g in ('DIR /ad /b /s "*holder"') do FOR /f "tokens=*" %%h in ('DIR /a-d /b "%%g"') do ECHO COMPACT /u "%%g\%%h"
测试脚本:
FOR /f "tokens=*" %%g in ('DIR /ad /b /s "*holder"') do COMPACT /c "%%g"
echo.
echo Set compress attribute of folders whose name ends in holder.
echo.
pause
FOR /f "tokens=*" %%g in ('DIR /ad /b /s "*holder"') do FOR /f "tokens=*" %%h in ('DIR /a-d /b "%%g"') do COMPACT /c "%%g\%%h"
echo.
echo Compress and set compress attribute of files in folders whose folder name ends in holder.
echo.
pause
FOR /f "tokens=*" %%g in ('DIR /ad /b /s "*holder"') do COMPACT /u "%%g"
echo.
echo Unset compress attribute of folders whose name ends in holder.
echo.
pause
FOR /f "tokens=*" %%g in ('DIR /ad /b /s "*holder"') do FOR /f "tokens=*" %%h in ('DIR /a-d /b "%%g"') do COMPACT /u "%%g\%%h"
echo.
echo Un-compress and un-set compress attribute of files in folders whose folder name ends with holder.
exit /b