سؤال

I want to write .bat file, I have two folders which names are A and B. I have pictures on A , and I want to transfer them from A to B in every 10 minutes, But I want to transfer the last 20 pictures. Pictures names are 1.jpg 2.jpg ,,,,90.jpg How can I do that? Is it possible?

thanks

هل كانت مفيدة؟

المحلول

@ECHO OFF
SETLOCAL
SET "sourcedir=c:\sourcedir"
SET "destdir=c:\destdir"

SET /a numbertomove=20

FOR /f "tokens=1*delims=:" %%a IN (
  'dir /b /a-d /o-d "%sourcedir%\*.jpg"^|findstr /n "."'
  ) DO (
 IF %%a leq %numbertomove% ECHO MOVE "%sourcedir%\%%b" "%destdir%\"
)
GOTO :EOF

The required MOVE commands are merely ECHOed for testing purposes. After you've verified that the commands are correct, change ECHO MOVE to MOVE to actually move the files. Append >nul to suppress report messages (eg. 1 file moved)


Edited to remove self-scheduling.

نصائح أخرى

to move the files you can use:

for /l %%i in (71,1,90) do move a\%%i.jpg b\%%i.jpg

For scheduling a task to run every 10 minutes see schtasks /create /?. There are a lot of options, collect them to your needs.

It's a bit confusing to get the right syntax if you do it the first time, so you may have to ask a new question if you know, which options you want to use.

(NOTE: to use the forconstruct on commandline (not in batch) use single% instead of %%)

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top