?
Solved

batch file for recursiv copy of files to target folder

Posted on 2008-10-06
3
Medium Priority
?
480 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 2000 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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

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…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

771 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