Solved

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

Posted on 2014-02-27
3
270 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
[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 54

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

The way I use Experts Exchange to assist me in analyzing and diagnosing a problem is I first enter a Verbose Question at Experts Exchange like: Office 2007 will hang when opening and saving files I then launch WordPad (any text editor will do) an…
Citrix XenApp, Internet Explorer 11 set to Enterprise Mode and using central hosted sites.xml file.
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…
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…

749 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