Batch script to move 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

Batch script to move files

#1 Post by jeff p » 28 Jul 2009 10:27

Hello

Sorry for the simple question.. been searching the web for days with no solution.

I have a thousand file animation sequence ie: Anim_0001.jpg - Anim_1000.jpg ( located in C:\AnimationFolder )
I’d like to move every 40 files to another existing directory, via Batch script (and overwrite any files that are already there)

Ie:

Anim_0001.jpg - Anim_0040.jpg goes to C:\ folder1
Anim_0041.jpg - Anim_0080.jpg goes to C:\ folder2
Anim_0081.jpg - Anim_0120.jpg goes to C:\ folder3

…etc.

Is this possible?


Thanks for any help

Jeff

rfpd
Posts: 78
Joined: 06 Jul 2009 16:19
Location: Lisbon, Portugal
Contact:

Resposta

#2 Post by rfpd » 28 Jul 2009 16:25

If you want without confirmation:


Code: Select all

move "your_file" "folder"



or


Code: Select all

move /Y "your_file" "folder"



If you want with confirmation:



Code: Select all

move /-Y "your_file" "folder"



Wink :wink:

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

#3 Post by jeff p » 29 Jul 2009 08:08

Thanks for the reply.



Not sure I understand this… did I mention I was a complete noob?

Could you please clarify what the script would be?

Thanks

Jeff

avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

#4 Post by avery_larry » 29 Jul 2009 12:13

That was rather fun. Here's one method:


Code: Select all

@echo off
setlocal enabledelayedexpansion

set "sourcedir=c:\animationfolder"
set "destdir=c:\folder"

cd /d "%sourcedir%
for %%a in (*) do (
   for /f "tokens=2 delims=_." %%b in ("%%~a") do set /a "folderext=(10000%%b %% 10000 - 1) / 40 + 1"
   md "%destdir%!folderext!" >nul 2>nul
   move /y "%%~a" "%destdir%!folderext!"
)


The filename MUST have the incremental number between a single underscore and a single period:

whatever_0010.whatever

AND it will choke if the incremental number starts with 0 (or if the incremental number gets really large). In theory this will work for incremental numbers with 5 digits.

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

#5 Post by jeff p » 29 Jul 2009 22:14

Thanks for the script, Avery_Larry!

... worked far better than the one rfp provided.

In fact it works exactly as i'd hoped.

If I could possibly bother you with one small addition. Actually i needed this initially, but didn't want to appear too greedy.

If possible could you provide an addition that renames the files increments, in each folder.?
Currently the entire sequence is spread across multiple folders. Anim_0001.jpg - Anim_1000.jpg

.I'd like to have the sequence in each destination folder, begin with Anim_0001.jpg

ie:
Folder1: Anim_0001.jpg - Anim_0041.jpg
Folder2: Anim_0001.jpg - Anim_0041.jpg
Folder3: Anim_0001.jpg - Anim_0041.jpg

note, that the amount of files per folder may vary. I may create sequence groups of 40 files, or 60, etc.

Thanks again for the code!!

Jeff

jaffamuffin
Posts: 40
Joined: 25 Jan 2008 14:05

#6 Post by jaffamuffin » 30 Jul 2009 05:46

this should be able to be adapted.

Code: Select all

@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
:mainloop
echo %~n1
SET folderno=%~n1

cd /d %1


SET batchcount=10001
:LOOP
SET pagecount=10001

IF NOT EXIST *.tif GOTO :DONE

FOR /F %%A IN ('dir /b /on /a-d') DO (
   SET bcount=!batchcount:~1!
   SET pcount=!pagecount:~1!
   
   IF NOT EXIST !folderno!_!bcount! mkdir !folderno!_!bcount!
   IF !pagecount! LEQ 10020  MOVE %%A !folderno!_!bcount!\!pcount!.tif
   SET /A pagecount=pagecount+1
)

SET /A batchcount=batchcount+1
GOTO :LOOP


:DONE
ECHO ALL FILES MOVED FOR !folderno!
GOTO :EOF
pause



this takes a folder with 1000 images (say) and the creates sequential directories inside it, and moves batches of 20 images into each one, sequnetially numbered.

rfpd
Posts: 78
Joined: 06 Jul 2009 16:19
Location: Lisbon, Portugal
Contact:

what

#7 Post by rfpd » 30 Jul 2009 11:43

what a **censored**?????''
i helped you and i am rfpd don't you read you ask hou move files e said to you how move files get out of this forum this forum is not for stupid people!

rfpd
Posts: 78
Joined: 06 Jul 2009 16:19
Location: Lisbon, Portugal
Contact:

fb

#8 Post by rfpd » 30 Jul 2009 11:44

*how and *and

avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

Re: what

#9 Post by avery_larry » 30 Jul 2009 12:59

rfpd wrote:what a **censored**?????''
i helped you and i am rfpd don't you read you ask hou move files e said to you how move files get out of this forum this forum is not for stupid people!
Calm down. You utterly and completely missed what the question was in the original post. You, in fact, did not help but rather added confusion. I know English is not your first language, so please don't assume the worst.

avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

#10 Post by avery_larry » 30 Jul 2009 13:08

To also rename the files:

Code: Select all

@echo off 
setlocal enabledelayedexpansion

set "sourcedir=c:\animationfolder"
set "destdir=c:\folder"

cd /d "%sourcedir%
for %%a in (*) do (
   for /f "tokens=1,2* delims=_." %%b in ("%%~a") do (
   set /a "folderext=(10000%%c %% 10000 - 1) / 40 + 1" && set /a "newincr=(10000%%c %% 10000 - 1) %% 40 + 1"
      md "%destdir%!folderext!" >nul 2>nul
      set newincr=000!newincr!
      move /y "%%~a" "%destdir%!folderext!\%%~b_!newincr:~-4!.%%~d"
   )
)

rfpd
Posts: 78
Joined: 06 Jul 2009 16:19
Location: Lisbon, Portugal
Contact:

ok

#11 Post by rfpd » 30 Jul 2009 17:03

ok

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

#12 Post by jeff p » 30 Jul 2009 22:11

Thanks, Avery_Larry

Works terrific.

The last code you provided is wrapped nicely into one...

Thanks again for the help!

Jeff

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

#13 Post by jeff p » 30 Jul 2009 22:17

Sorry, rfpd

Didn't mean to be offensive with reference to your code.

Your response resembled a hunerous remark... I thought i would extend this with my own brand of wit.

But yes, you're right, I certainly don't belong in these forums....lol

Although, I wouldn't consider myself stupid... perhaps, Script Challenged


:wink:

Jeff

rfpd
Posts: 78
Joined: 06 Jul 2009 16:19
Location: Lisbon, Portugal
Contact:

ok

#14 Post by rfpd » 31 Jul 2009 03:55

ok!

Post Reply