Windows 将cmd compact与文件夹名称模式一起使用
我的文件夹结构如下: 如何仅在名称以“Holder”结尾的文件夹上使用Windows 将cmd compact与文件夹名称模式一起使用,windows,cmd,Windows,Cmd,我的文件夹结构如下: 如何仅在名称以“Holder”结尾的文件夹上使用compact/s/c递归压缩这些文件夹中的所有文件?谢谢Windows 10 64位 使用compact和cmd为循环设置文件夹和/或文件压缩属性 为名称以holder结尾的每个文件夹设置compress属性。压缩文件夹名称以holder结尾的每个文件夹中的非系统文件或隐藏文件。如果COMPACT遇到错误,请停止 命令: 脚本: FOR /f "tokens=*" %%g in ('DIR /ad /b /s "*hold
compact/s/c
递归压缩这些文件夹中的所有文件?谢谢Windows 10 64位
使用compact和cmd为循环设置文件夹和/或文件压缩属性
为名称以holder
结尾的每个文件夹设置compress属性。压缩文件夹名称以holder
结尾的每个文件夹中的非系统文件或隐藏文件。如果COMPACT遇到错误,请停止
命令:
脚本:
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
您需要研究的问题是“如何列出名称以已知字符串结尾的目录”。您的实际任务与此无关,您只需要知道这一点,然后调整所学内容以合并
compact
命令。使用compact/?
并阅读filename
参数。pattern
是什么意思?使用@Compo-suggest,以下工作:对于/d%G in(“*Holder”)做cd%G&&cmd/s/c&&cd..
。谢谢没问题,ShanLuh,我建议您不要考虑更改目录,除非它对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