script to move files with modulus
Moderator: DosItHelp
script to move files with modulus
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)...
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)...
Last edited by doscode on 06 Sep 2012 02:14, edited 2 times in total.
Re: script to rename files
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.
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
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
gives syntax error
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
@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
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
I know there's a lot of mistakes yet, but can you tell me what mistakes are in the ocde?
Command
set /a remains = c % 6
shows error:
Operator not found
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
Last edited by doscode on 06 Sep 2012 04:25, edited 2 times in total.
Re: script to move files with modulus
Or should it be like so with delayedexpansion
But the arithmetic does not work here and echo displays c+1
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
Last edited by doscode on 06 Sep 2012 04:25, edited 1 time in total.
Re: script to move files with modulus
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
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
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
Your directory spec is using unix path separators.
./moved/%%B
should be:
"moved\%%B"
./moved/%%B
should be:
"moved\%%B"
Re: script to move files with modulus
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
)