1.

Solve : Help with batch script to move files (win xp)??

Answer»

i am trying to divide 2000+ files from a folder and move them to other FOLDERS (35 files per folder)

e.g., move files from \src_folder\*.* (2000 files)
to \src_folder\dest_folder0\*.* (35 files)
\src_folder\dest_folder1\*.* (35 files)
\src_folder\dest_folder2\*.* (35 files)
\src_folder\dest_folder3\*.* (35 files)
\src_folder\dest_folder4\*.* (35 files)
...
...

Can anyone help to write this batch script?ok, I can help - but as Im in the office, I can only point you in the direction you need to go, you will have to fill in the blanks !!

You want to process 35 files at a time, I assume it could be any 35, they ARENT in any particular grouping.

firstly, list your files into a text file
Dir /b >\$list$

(if you want them ordered, use the appropriate ordering switches in the dir)

now, a clever bit, create a blank file
echo.>\$blank$

you can use FC to compare the $blank$ and $list$ files to show the difference (all your files) but - we can limit this to the specific number of mismatches that you want, in your case, 35 :

fc /LB35 \$blank$ \$list$ > \$batch$

now, look at this file, it contains a few lines of preamble then the list of files you want to move; you can process this with a simple FOR loop

now repeat the process (you dont need to recreate the \$blank$ file) until there are no files left (if you are moving the files out, they wont appear on the next iteration of the dir) .... your LOGIC to control the iteration should also work out what the directory names are -- these might be created ALREADY, in which case you need to work out how to GRAB the names from a fiel or whatever, or you might just want to have them numbered - again you can do this in a FOR loop.

Sorry about leaving so much work for you, but Im a bit rushed ... if its a 1-off job, just use windows explorer, it will be quicker

Happy new year
GrahamWhen this is all said and done, that is, working good, Please post here. I could use something like this myself.ionic
Why not try to do it yourself and share with the rest of us ??

GrahamSeems unfair the OP should have to wait for a response which may or not ever come.

Code: [Select]@echo off
setlocal enabledelayedexpansion
set fldrct=0
set filect=0
md \src_folder\dest_folder%fldrct%

for /f "tokens=* delims=" %%x in ('dir /b \src_folder\*.*') do (
call set /a filect=%%filect%%+1
if !filect! gtr 34 (
call set /a fldrct=%%fldrct%%+1
md \src_folder\dest_folder!fldrct!
set /a filect=0
)
copy \src_folder\%%x \src_folder\dest_folder!fldrct!
)

The code uses copy, not move so as to keep the original data intact. I dislike writing destructive code for other people's machines.

Good luck. Quote from: gpl on January 02, 2008, 09:15:03 AM

ionic
Why not try to do it yourself and share with the rest of us ??

Graham

Mostly because I am not that smart eith batch code.
I do, however, learn from the code.

Sidewinder, thanks for your time and efforts.

Christine W
, I hope Sidewinder's efforts work out superbly for you. I didn't intend to hijack your thread!That's OK ionic, I didn't mind it at all.

Sidewinder's script works perfectly.
It has saved me a lot of time to manually move files from windows explorer. Thank you.


Discussion

No Comment Found