Solved

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

Posted on 2014-02-27
3
261 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 51

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

Highfive Gives IT Their Time Back

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

Many times while working on a computer regardless of any Operating System, lag and crashes seem to creep in, hindering your working speed. Sometimes, it can also cause your work to be lost unexpectedly and as a result, you are unable to meet your de…
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 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

757 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

20 Experts available now in Live!

Get 1:1 Help Now