Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
hello, i am moving files with a batch and scheduled tasks. is there a way to select a specific # of files instead of all the say *.html files in a directory? the string i am using is
move /-y *.html (directory)
thanks

If you could explain yourself better I or someone else could help you out. When you say number of files do you mean they are are named by numbers, only move the first 5 in the folder, or something else. Shouldn't be hard to do when you explain some more.

sorry, say there 100 .html files, i want to select the first 20 and move them then select the next 20 etc...

well this following script will move the entered number html files from the folder the script is in to a folder you choose.
----------------
@echo offecho enter number of files to move
set /p ep=set cout=0
setlocal enabledelayedexpansion
for /f "tokens=*" %%x in ('dir /b *.html') do (
move "%%x" (DIRECTORY)
set /a cout=!cout!+1
if !cout!==%ep% goto end
):end
pause
----------------if you wish to move the same number each time replace this
echo enter number of files to move
set /p ep=with just
set ep=(NUMBER)
There is one oddity to how it moves the files. If you have files with numbers like 001, 002, ..., 099, 100 there will be no issue. If your files are named like 1,2,3,...,98,99,100. This script will move 1,10,11,12,...,19,100 since that is how it "sees" the file listed.For regular letter names they will be moved in alphabetical order.
Let me know how this works and if there is anything that can be imporved (other than the order thing since that is dos/cmd related, It could be scripted to work but i'm not that good)

Depands on how you define 'first 20'.
Anyway, no need to initialize the count.
==================================
@echo off
setLocal EnableDelayedExpansionfor /f "tokens=* delims= " %%a in ('dir/b *.html') do (
set /a N+=1
if !N! geq 20 goto :eof
echo move %%a d:\dest
)
=====================================
If at first you don't succeed, you're about average.M2

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |