Hi,
Been a while since I last posted. Sorry to come asking for help like this but after something unfortunate that occurred (family related) it's found me needing a way to move a directory of sequentially named images (that vary in total number depending on the export to that directory) from a directory into three sub-directories, in three groups (roughly one third each into each sub-directory).
I looked around for a way to achieve this, and came as far as enumerating the number of files in the source directory and dividing it by three but I end up without the complete number of files per group that way for some totals due to the apparent rounding of the 1/3 value.
I also found this post which describes performing a loop of commands based on a fixed number of per file group iterations.
Is there a way to reconcile the concept, so that for example when the directory has 394 total image files the first group moved would be the first 131 files, the second group the next 131 images, then the last 132? Basically accounting for non-whole values in the groupings by appending the remaining file to the last group moved when splitting by a third?
Haven't gotten to the move commands yet but currently encountered this issue when testing the calculation. Perhaps the solution obvious but I'd appreciate any insight with this. Thanks.
[Resolved] Moving incrementally named files to three different directories, evenly
Moderator: DosItHelp
[Resolved] Moving incrementally named files to three different directories, evenly
Last edited by koko on 30 Jun 2019 08:19, edited 2 times in total.
Re: Moving sequentially named files to three different directories, evenly
Not sure what "sequentially named" and "image files" means in particular because you didn't provide any example.
If you are only looking for the math, then it's quite easy.
If "image files" is anything else but *.jpg (e.g. *.png, *.gif, or whatever) then you have to update the DIR command accordingly.
Steffen
If you are only looking for the math, then it's quite easy.
Code: Select all
for /f %%i in ('dir /a-d /b *.jpg^|find /c /v ""') do set /a "third=%%i/3, remaining=%%i-2*third"
echo %third% %third% %remaining%
Steffen
Re: Moving sequentially named files to three different directories, evenly
Thank you very much. By 'sequential' I now realize I should have written 'incremental' to be more accurate/clear. I updated the topic title.aGerman wrote: ↑30 Jun 2019 07:22Not sure what "sequentially named" and "image files" means in particular because you didn't provide any example.
If you are only looking for the math, then it's quite easy.If "image files" is anything else but *.jpg (e.g. *.png, *.gif, or whatever) then you have to update the DIR command accordingly.Code: Select all
for /f %%i in ('dir /a-d /b *.jpg^|find /c /v ""') do set /a "third=%%i/3, remaining=%%i-2*third" echo %third% %third% %remaining%
Steffen
In my case the files are named '0000.jpg' to '0394.jpg' (for example). The code for enumerating the directory is such when I wrote the OP (the structure of the for loop sourced from a post elsewhere):
Code: Select all
@echo off
setlocal enabledelayedexpansion
set "source=<pathtodirectoryhere>"
for /f %%A in ('dir "!source!" ^| find "File(s)"') do set totalfiles=%%A
echo File count = !totalfiles!
Appears to run perfectly. Thanks again for the direction!