Move incremental files?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
jeff p
Posts: 42
Joined: 28 Jul 2009 10:21

Move incremental files?

#1 Post by jeff p » 09 Jul 2012 07:41

I'm in desperate need of a batch file to cut and paste files..

I have a sequence of over 5000 images in one folder.
(ie: image_0001.jpg, image_0002.jpg, etc)

And I'd like to be able to move every 48th image to its own folder, in another directory.

Is something like this possible?

Thanks for any help.

Jeff

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Move incremental files?

#2 Post by foxidrive » 09 Jul 2012 07:55

This might work (untested):

Code: Select all

@echo off
setlocal enabledelayedexpansion
md temp1
for /f "delims=" %%a in ('dir /b image*.jpg') do (
set /a c=c+1
if !c! EQU 48 (
move "%%a" temp1
set c=0)
)
Last edited by foxidrive on 09 Jul 2012 08:39, edited 1 time in total.

jeff p
Posts: 42
Joined: 28 Jul 2009 10:21

Re: Move incremental files?

#3 Post by jeff p » 09 Jul 2012 08:13

Thanks Foxdrive!

May I ask how to include the path directories? Or do I run it from the root directory?

Asuming my source folder is D:\Tests
and destination folder is D:\Tests\Finals

Sorry, I should have mentioned I'm a complete noob.

Thanks again for the reply!

Jeff

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Move incremental files?

#4 Post by foxidrive » 09 Jul 2012 08:37

Put it in the folder with the images. It will create a temp1 folder with the 48th series of images, with any luck.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Move incremental files?

#5 Post by foxidrive » 09 Jul 2012 08:40

Or use this. Note that I edited the above version to correct an error.


Code: Select all

@echo off
pushd "d:\tests" && (
setlocal enabledelayedexpansion
md Finals 2>nul
for /f "delims=" %%a in ('dir /b image*.jpg') do (
set /a c=c+1
if !c! EQU 48 (
move "%%a" Finals
set c=0)
)
)

jeff p
Posts: 42
Joined: 28 Jul 2009 10:21

Re: Move incremental files?

#6 Post by jeff p » 09 Jul 2012 09:11

Thanks Foxdrive!

Your latest code worked exactly how I described..

thanks again!!

Jeff

Post Reply