-4

I have a folder "C:\TEST\Clean" with many photos (let's say 436) and I have to move 30 of them to the folder "C:\Dropbox\Apps\AutoPost\For_Post_1".

I have this so far but it's for 1 file and I need it for 30.

@echo off
set folder=C:\TEST\Clean
set destfolder=C:\Dropbox\Apps\AutoPost\For_Post_1

for /f "delims=" %%C in ('dir /b /a-d "%folder%\*.jpg" ^| find /c /v ""') do set /A num=%random% %% %%C
for /f "delims=" %%F in ('dir /b /a-d "%folder%\*.jpg" ^| more +%num%') do set name=%%F & goto next

:next

echo Wallpaper is now %name%
move "%folder%\%name%" "%destfolder%\%name%"
6
  • 1
    We are not a coding service. What do you have so far? (I didn't downvote yet, but this happens every time for such questions)
    – Varon
    Mar 19, 2016 at 23:18
  • Hi Varon, maybe i missunderstand something and you have to devote me question. I've done nothing because i don't know how to do it. I google it but i had no luck (i din't understand some results). If you can help me (you or someone else here), plsease do or tell me if i have to delete somehow my question from the platform. Thanks again. Mar 19, 2016 at 23:23
  • "StackExchange" and sub-sites constitute a help platform. What you want to have is a complete bat-file that do these things for you. You didn't contribute ideas. Do you understand what I mean? If I go to a software company and pay 100$ I can ask for such a bat-file, but if I want to get help I would say: I tried this and this... here I think something goes wrong... I don't understand this line... --- This is the difference
    – Varon
    Mar 19, 2016 at 23:47
  • 1
    Thanks Varon, i got it. I have so far the above but move only 1 photo. Can you please help me to move 30 of them at once? @echo off set folder=C:\TEST\Clean set destfolder=C:\Dropbox\Apps\AutoPost\For_Post_1 for /f "delims=" %%C in ('dir /b /a-d "%folder%*.jpg" ^| find /c /v ""') do set /A num=%random% %% %%C for /f "delims=" %%F in ('dir /b /a-d "%folder%*.jpg" ^| more +%num%') do set name=%%F & goto next :next echo Wallpaper is now %name% move "%folder%\%name%" "%destfolder%\%name%" Mar 19, 2016 at 23:50
  • so if the mentioned code works for 1 file, why not just run the same code in a loop for 30 iterations
    – SeanClt
    Mar 20, 2016 at 1:11

1 Answer 1

1

You can use the following script to execute 30 times the snippet you have already written:

@ECHO off
SET src=C:\TEST\Clean
SET dst=C:\Dropbox\Apps\AutoPost\For_Post_1
SET ext=*.jpg

FOR /L %%G IN (1,1,30) DO (call :subroutine "%%G")
GOTO :eof

:subroutine
    FOR /f %%A IN ('dir /b /s %src%\%ext% ^| find /v /c ""') DO SET cnt=%%A
    FOR /f "delims=" %%C IN ('dir /b /s "%src%\%ext%" ^| find /c /v ""') DO (
      SET /A num=%ranDOm% %% %%C
      FOR /f "delims=" %%F IN ('dir /b /s "%src%\%ext%" ^| more +%num%') DO SET name=%%F & GOTO next
    )   
    :next
    ECHO Round %1 : File %name%
    MOVE %name% %dst%
    EXIT /B

:eof

Best explanation for for-loops I've found: http://ss64.com/nt/for.html
EXIT /B is available in Windows 2000 and later and is similar to a common return

2
  • would you normally use a batch file to do that, or would you use another language, if so, what?
    – barlop
    Mar 20, 2016 at 3:19
  • @barlop I think I would rather use the Windows Explorer language of dragging and dropping :) Oct 26, 2016 at 16:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .