Windows Batch file to move X number of files from folder to folder

前端 未结 3 1286
没有蜡笔的小新
没有蜡笔的小新 2021-01-14 15:48

I\'m trying to use a batch file to move files in blocks of 30 if there are less than 20 files in %DataLoc%. I modified code from a prior question. The problem

3条回答
  •  孤独总比滥情好
    2021-01-14 16:52

    I updated the code and got it to work by changing some things. Thanks Andy for the tips but I could not get it to work with the suggestions - I wouldn't be surprised if I did not follow them and that is on MY side, not yours.

      FOR /F %%G IN ('DIR /B "%HoldLoc%"\*.tmp') DO IF !SrcCount! LSS %SrcMax% (
       SET /A SrcCount += 1 
       Echo "%HoldLoc%"
       Echo "%%G%"
       Echo "%SrcCount%
       move /y "%HoldLoc%"\"%%G" "%DataLoc%"
    

    )

    Here is what I ended up with - longer but still functional:

    SETLOCAL ENABLEEXTENSIONS
    SETLOCAL ENABLEDELAYEDEXPANSION
    
    echo on
    set DataMax=50
    set DataLoc=C:\Test Data (x86)
    Set HoldLoc=C:\Test Hold
    set count=0
    FOR /F %%a in ('DIR /B "%DataLoc%"\*.tmp') do set /A count=count+1
    if %count% GEQ %DataMax% (Goto Exit) else (GOTO FMove)
    :FMove
    Echo Gather Top 30 files
    set SrcCount=0
    set SrcMax=30
    FOR /F "TOKENS=*" %%a IN ('dir /A-D /O-D /B "%HoldLoc%"\*.tmp') DO (
            SET /A SrcCount += 1
            if !SrcCount! LEQ %SrcMax% (
            MOVE /y "%HoldLoc%\%%a" "%DataLoc%"
            )
        )
    goto Exit
    :Exit
    close
    

提交回复
热议问题