Solved

batch file for recursiv copy of files to target folder

Posted on 2008-10-06
3
472 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

770 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