Solved

Move and redistribute all files from a folder (and its subfolders) to one of 4 other folders.

Posted on 2014-02-27
3
267 Views
Last Modified: 2014-06-11
I would like a Windows batch file for DOS (not Powershell)  to move distribute files evenly  from folder S:\SOURCE to folders D:\Dest1, D:\Dest2, D:\Dest3, D:\Dest4  INCLUDING files WITHIN SUBDIRECTORIES (duplicate filenames need not be moved).  

I.e., all files (including files within subfolders) from S:\SOURCE are moved and nearly evenly distributed among each of the 4 destination folders. If there are 1000 files in all of the subdirectories of  S:\SOURCE then after the batch file is run, all of the 1000 files will be removed from S:\SOURCE and each of the folder D:\Dest1, .... D:\Dest4 will have approximately 250 files.

I prefer this to be done with a DOS .bat file rather than Powershell
0
Comment
Question by:wind-surfer
3 Comments
 
LVL 53

Accepted Solution

by:
Bill Prew earned 50 total points
ID: 39893764
This should do what you described.  Adjust the directory names near the top, then test it well to make sure I understood what you wanted.

@echo off
setlocal EnableDelayedExpansion

set BaseDir=S:\Source
set DestDir[0]=D:\Dest1
set DestDir[1]=D:\Dest2
set DestDir[2]=D:\Dest3
set DestDir[3]=D:\Dest4

set Count=-1
for /f "tokens=*" %%A in ('dir /a-d /b /s "%BaseDir%\*.*"') do (
  set /a Count+=1
  set /a Dest=Count %% 4
  for %%B in (!Dest!) do (
    if not exist "!DestDir[%%B]!\%%~nxA" (
      move "%%~A" "!DestDir[%%B]!"
    )
  )
)

Open in new window

~bp
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Capture New Directory and set variable 21 70
URL to download Windows 10 Home 2 151
how to find then copy to anotehr file 3 52
Copy dir and files with robocopy 2 56
TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
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…
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …

809 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