【发布时间】:2015-03-25 15:11:44
【问题描述】:
如果文件名中的日期时间已过,需要一个脚本来移动文件。
这是我尝试过的,但它总是移动所有文件。
@ECHO OFF
set hr=%time:~0,2%
if "%hr:~0,1%" equ " " set hr=0%hr:~1,1%
SET CurrTime=%date:~-4,4%%date:~-10,2%%date:~-7,2%%hr%%time:~3,2%%time:~6,2%
FOR /F "tokens=*" %%G IN ('dir /b E:\FileLoc\A_ChangePrice_*txt') DO (
SET "LL=%%G"
SET CurrFileTime=%LL:~16,-4%
SET "FileTime=%%CurrFileTime%%"
CALL ECHO %CurrTime%
CALL ECHO %FileTime%
IF %CurrTime% GTR %FileTime% (MOVE E:\FileLoc\%%G CALL ECHO F:\PriceChanges\%%G)
)
当前时间=20150325104003 文件时间=20160425192500
我发现这个脚本有 2 个问题。
- 脚本第一次运行 FileTime 为空?!
- 即使 FileTime 更大,它也会移动文件。
可能有比这更简单的解决方案,我愿意提供建议。
提前致谢。
【问题讨论】:
标签: date batch-file math cmd compare