@echo off
setlocal enableextensions disabledelayedexpansion
rem Three alternatives
rem Pure arithmetics
set "numFiles=7"
for /f "delims=" %%a in ('dir /b /o-d /a-d') do (
2>nul set /a "1/numFiles", "numFiles-=!!numFiles" && (
echo copy "%%~fa" x:\somewehere
)
)
rem Pure arithmetics 2 - No negation operator
set "numFiles=7"
for /f "delims=" %%a in ('dir /b /o-d /a-d') do (
2>nul set /a "1/numFiles", "numFiles-=1" && (
echo copy "%%~fa" x:\somewehere
)
)
rem Number list of files
set "numFiles=7"
for /f "tokens=1,* delims=:" %%a in ('
dir /b /o-d /a-d
^| findstr /n "^"
') do if %%a leq %numFiles% (
echo copy "%%~fb" x:\somewehere
)
あなたは 'disabledelayedexpansion'をしましたが、それは言及するのである算術ソリューションは、二重ではないオペレータ作業' !! ' – LotPings
@LotPingsを持っているために、これを必要ないことを、申し訳ありませんが、私はあなたを誤解。あなたは正しいですが、それは私がほとんど常にコードワークの下でコンテキストを定義する 'setlocal'を含む理由の1つです。また、本当に必要な場合を除いて遅延拡張を無効にすることは、私の悪い習慣の1つです。 –
トリプルありがとう!それは期待どおりに動作します。 – furbik