Solved

batch file for recursiv copy of files to target folder

Posted on 2008-10-06
3
478 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

732 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