Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2014-02-27
3
Medium Priority
?
275 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 58

Accepted Solution

by:
Bill Prew earned 200 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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

INTRODUCTION The purpose of this document is to demonstrate the Installation and configuration of the Data Protection Manager product. Note that this demonstration was prepared on the basis of Windows OS is 2008 R2 and DPM 2010. DATA PROTECTI…
YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
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…

604 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