2016-06-13 68 views
0

我有一個批處理文件,如果文件名包含數字,則會將.tiff/tif文件從一個文件夾移動到另一個文件夾,例如, 0000002341567.tif。它工作正常,但 我的要求是移動文件,即使它有一個名稱,如000000234156-7或0000002341567-s 所以說文件名可以後綴爲 - 和一個數字編號或連字符和一個字符。將名稱中帶有連字符的tiff/tif文件移動到

for %%I in ("C:\Documents\Pictures\*.tif*") do (
    if !FileCount! EQU 0 (
     echo Exiting after having moved already %FileCount% TIF files. 
     goto LoopEnd 
    ) 
    set "HasOnlyDigits=1" 
    for /F "tokens=1 delims=" %%T in ("%%~nI") do set "HasOnlyDigits=%%T" 
    if "!HasOnlyDigits!" == "1" (
     move /Y "%%I" "%FolderGood%" 
    ) 

回答

0

findstr有一組非常有限的正則表達式,但它足以完成這個任務:

@echo off 
set filecount=1 
setlocal enabledelayedexpansion 
for %%I in ("*.tif*") do (
    if !FileCount! EQU 0 (
     echo Exiting after having moved already %FileCount% TIF files. 
     goto LoopEnd 
    ) 
    echo %%~nI|findstr /R "^[0-9][0-9]*-.$" >nul && (
     echo yes %%I 
     ECHO move /Y "%%I" "%FolderGood%" 
     set filecount+=1 
    ) || (
     echo no %%I 
    ) 
) 
:loopend 

這裏正則表達式包括:

^開始行(串)的
[0-9]任何數字
[0-9]*任何數字(零或任何數字的任何數字)(前[0-9],以確保有最小值一位)
-破折號
.任何字符
$行結束(字符串)

相關問題