Page 1 of 1

script to move files with modulus

Posted: 05 Sep 2012 16:35
by doscode
Can you help with this? I need script to move files into different folder. There are images exported from video, so they have number of frames, e.g. from a0000.jpg to .. a0997.jpg

and I would like to go from a0000.jpg to .. a0997.jpg and move every
2nd - 7th image. (one image skipped in the folder, next 6 images moved to folder, and so on)...

Re: script to rename files

Posted: 05 Sep 2012 17:38
by Squashman
Your title says rename but your description says move.
A single for loop with a counter should do the trick.
Then use two nested IF statements to see if your counter is between 2 and 7.
Keep adding 1 to the counter at the beginning of the loop and reset the counter to zero when it gets to 7.

Re: script to rename files

Posted: 06 Sep 2012 02:08
by doscode
Yes, I changed from rename to move, because it is more effective. Can you advice SET calculation for modulus? How to calculate this
remains = x modulus 6

I am trying something like

Code: Select all

REM SET /A r = %%x %%%% 6
SET /A X = 6
echo 1)
SET /A r = %%x %%%% 6
echo %%x
echo 2)
SET /A r = %%x %%% 6
echo %%x


gives syntax error

Re: script to move files with modulus

Posted: 06 Sep 2012 02:46
by abc0502
@doscode
set /a command doesn't take variable like "%%a" or %var% it must be only text without %% or !! signs

so set the %%x to a variable name such as "var", then

Code: Select all

set /a result = var % 6

Re: script to move files with modulus

Posted: 06 Sep 2012 03:52
by doscode
I know there's a lot of mistakes yet, but can you tell me what mistakes are in the ocde?

Code: Select all

@echo off
mkdir moved
SET c=0

FOR /F %%B IN ('dir *.jpg /b /o:n') DO (
SET c=c+1
set /a remains = c %% 6
IF %%remains NEQ 0 ( move %%B /moved )
)
pause


Command
set /a remains = c % 6
shows error:
Operator not found

Re: script to move files with modulus

Posted: 06 Sep 2012 04:09
by doscode
Or should it be like so with delayedexpansion

Code: Select all

Setlocal EnableDelayedExpansion
@echo off
mkdir moved
SET c=0

FOR /F %%B IN ('dir *.jpg /b /o:n') DO (
SET /A c=!c!+1
echo !c!
set /a remains = c % 6

REM IF !remains! NEQ 0 move %%B /moved

)


pause


But the arithmetic does not work here and echo displays c+1

Re: script to move files with modulus

Posted: 06 Sep 2012 04:25
by doscode
OK I fixed it but I have problem. I have run the script and my files disapeared, they are not in the folder moved.

Edit:
New fix

Code: Select all

Setlocal EnableDelayedExpansion
@echo off
mkdir moved
SET c=0

FOR /F %%B IN ('dir *.jpg /b /o:n') DO (
SET /A c=!c!+1
echo !c!
set /a remains = c % 6

REM IF !remains! NEQ 0 move %%B ./moved/%%B
)

Re: script to move files with modulus

Posted: 06 Sep 2012 06:15
by Squashman
I understand the logic you are trying to use but it doesn't match the description of your initial question.

Re: script to move files with modulus

Posted: 06 Sep 2012 06:43
by foxidrive
Your directory spec is using unix path separators.

./moved/%%B

should be:

"moved\%%B"

Re: script to move files with modulus

Posted: 06 Sep 2012 06:51
by foxidrive
Does this work?


Code: Select all

@echo off
Setlocal EnableDelayedExpansion
mkdir moved
SET c=1
FOR /F "delims=" %%B IN ('dir *.jpg /b /o:n') DO (
if not !c! EQU 1 echo move "%%B" "moved\"
SET /A c=c+1
if !c! EQU 8 set c=1&pause
)