批处理文件 – Windows CMD – 在for循环中设置不起作用
发布时间:2020-12-13 22:39:15 所属栏目:Windows 来源:网络整理
导读:我想编写批处理文件,它将循环遍历包含备份目录的所有目录,并删除其中超过X天的文件. 在我想要运行我的脚本的计算机上,没有“forfile”命令. 没有Power Shell,因此CMD或VBScripts似乎只是完成此任务的方法. 目前我有“设置”语句的问题 – 似乎当我调用%chec
我想编写批处理文件,它将循环遍历包含备份目录的所有目录,并删除其中超过X天的文件.
在我想要运行我的脚本的计算机上,没有“forfile”命令. 没有Power Shell,因此CMD或VBScripts似乎只是完成此任务的方法. 目前我有“设置”语句的问题 – 似乎当我调用%checkpath%时,我没有收到预期的文件夹. rem we will memorize current directory pushd %cd% set folder="C:Documents and SettingsmynameDesktop" cd %folder% rem loop only folders with five chars within their names (unfortunately on less also for /D %%g in (?????) DO ( set checkpath="%cd%%%gbackup" if exist %checkpath% ( for %%a in ('%%gbackup*.*') do ( set FileDate=%%~ta set FileDate=%%FileDate:~0,10%% rem here I want to compare file modification data with current date ) ) popd pause 解决方法
您需要使用延迟扩展来读取您在for循环中设置的变量.
试试这个 setlocal enabledelayedexpansion rem we will memorize current directory pushd %cd% set folder="C:Documents and SettingsmynameDesktop" cd %folder% rem loop only folders with five chars within their names (unfortunately on less also for /D %%g in (?????) DO ( set checkpath="%cd%%%gbackup" if exist !checkpath! ( for %%a in ('%%gbackup*.*') do ( set FileDate=%%~ta set FileDate=!%FileDate:~0,10%! rem here I want to compare file modification data with current date ) ) popd pause 用您创建的变量替换%’,将表示它使用延迟扩展. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- windows-8 – 不允许在常规桌面应用程序中使用WinRT API的U
- windows – rake资产:预编译不起作用(rails 3.1.1)
- windows – 可以从独立服务器运行远程桌面网关吗?
- 在Win10上使用VS2015编译的C SDL2程序中调试加载时间错误
- Windows上Jenkins的git插件不使用带子模块的凭据
- windows – 使用组策略加入无线网络时,是否可以指定WPA2密码
- wcf – 使用RESTSharp上传图片(addFile)
- Hewlett Packard定制OEM Windows上的Delphi平台错误
- microsoft-graph – 图形API:PUT / beta / groups //团队认
- Microsoft Excel错误:“将命令发送到程序时出现问题.”
推荐文章
站长推荐
热点阅读