Solved

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

Posted on 2014-02-27
3
264 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 52

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Log files are useful in diagnosing and repairing problems.  This is a list of common log files and their standard locations that I've compiled.   While this is not exhaustive, it is a pretty good list that I've found to be useful.  I may update it f…
This article describes how to set permissions to allow a limited-permissions user to start and stop a particular System Service.   It is always best to give users only the permissions that they need to perform their job, so tweaking particular permi…
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…
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…

910 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

17 Experts available now in Live!

Get 1:1 Help Now