# Select 20 files for a folder and move them



## jat421 (Jun 14, 2008)

Hi,

I have a folder that has few hundred files and I would like to select 20 files by name from that folder and move them. I am little confused on how to do that. Any suggestions?


----------



## jat421 (Jun 14, 2008)

Actually maybe just move any 20 files and I can skip the "by name" part for now. Thanks!!


----------



## jat421 (Jun 14, 2008)

k, got something...looks like it's working!


```
SETLOCAL ENABLEEXTENSIONS
SETLOCAL ENABLEDELAYEDEXPANSION

Echo Gather Top 30 files
set to_print=c:\To print\testing
set printed=c:\To print\testing\Printed

set SrcCount=0
set SrcMax=30
FOR /F "TOKENS=*" %%a IN ('dir /A-D /O-D /B "%to_print%"\*.pdf') DO (
        SET /A SrcCount += 1
        if !SrcCount! LEQ %SrcMax% (
        MOVE /y "%to_print%\%%a" "%printed%"
        )
    )

pause
```


----------



## Squashman (Apr 4, 2003)

No Delayed Expansion or counter needed

```
Echo Gather Top 30 files
set to_print=c:\To print\testing
set printed=c:\To print\testing\Printed
PUSHD "%to_print%
for /f "tokens=1,2 delims=[]" %%G in ('dir /a-d-s-h /o-d /b *.pdf ^|find /v /n ""') do IF %%G LEQ 30  MOVE /Y "%%H" "%printed%"
popd
```


----------

