Solved

batch file for recursiv copy of files to target folder

Posted on 2008-10-06
3
466 Views
Last Modified: 2012-05-05
Hello Experts
i´m looking for a simple batch script to copy files from a source folder (include subfolders) into a target folder with ''dynamic'' subfolders.

the source file structure look like
\\myserver\myfolder

this folder contains several subfolders for example

/school/klasse1/teacher/....
/school/klasse2/teacher/....
/school/teacher/....

In these folders are many *.rtf files ( ~ 100000 files)

Now the heavy part. I have to copy all the rtf files to a target folder with several subfolders . For each folder the maximum count of files should not more than 1000 files.
For example:

\\myotherserver\target\klasse1\ not more than 1000 files
\\myotherserver\target\klasse2\ not more than 1000 files
...

is there any way to realize this.


0
Comment
Question by:bibabutze
3 Comments
 
LVL 21

Expert Comment

by:AmazingTech
ID: 22657284
So you don't care which folder it comes from and you don't care what order?

Any 1000 rtf files in klasse1 then another 1000 rtf files in klasse2

So with 100000 rtf files the last folder should be klasse100?
0
 

Author Comment

by:bibabutze
ID: 22657622
yes.
is there a solution for it
0
 
LVL 38

Accepted Solution

by:
Shift-3 earned 500 total points
ID: 22659755
Paste the script below into a text file with a .cmd extension.  Customize the value of the source variable with the root folder to copy from.  Customize the value of the dest variable with the directory to copy to (without the trailing number).  Running the script will copy the .rtf files to numbered folders.

Note that files with the same names will be overwritten if they get copied to the same destination folder.  If this is a problem please specify how you would like the script to handle it.


@echo off

setlocal enabledelayedexpansion
 

set source=\\myserver\myfolder\*.rtf

set dest=\\myotherserver\target\klasse
 

set filecount=0

set foldercount=1

set maxfiles=1000
 

for /F "tokens=*" %%G in ('dir "%source%" /A:-D /B /S') do (

 set /A filecount+=1

 xcopy "%%G" "%dest%!foldercount!\" /C /H /R /Y
 

 if [!filecount!]==[%maxfiles%] (

  set /A foldercount+=1

  set filecount=0

 )

)

Open in new window

0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

One of my most closely kept secrets is revealed in this discussion How to output text on the same line This question was recently posted in EE by Simon336697 (http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_2459…
VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now