Solved

batch to move folders based on folder name

Posted on 2013-11-11
2
795 Views
Last Modified: 2013-11-11
Hi I'm after a bit of batch scripting help..

I would like a script where that can move every single folder (that's got 2 more characters in it's name) into a folder that begins with the first letter of it's name.

EG.

J Bloggs
Joe Bloggs
Jane Bloggs
JA Bloggs

Will all be moved to a folder
J

If any folders already exist, it should overwrite the existing data.

Any help would be greatly appreciated.
0
Comment
Question by:antonioking
[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
2 Comments
 
LVL 85

Accepted Solution

by:
oBdA earned 500 total points
ID: 39639500
That should do it; the script is currently in test mode and will only display the "move" commands it would normally run. Remove the uppercase ECHO in line 11 to run it for real:
@echo off
setlocal enabledelayedexpansion
REM The folder where the user folders are:
set UserFolder=C:\Temp
REM the folder in which the "Initial" folders will be created: 
set TargetRoot=D:\Temp
for /d %%a in ("%UserFolder%\*.*") do (
	echo Processing %%a ...
	set TargetFolder=%%~nxa
	set TargetFolder=%TargetRoot%\!TargetFolder:~0,1!
	ECHO move "%%~a" "!TargetFolder!"
)

Open in new window

0
 

Author Closing Comment

by:antonioking
ID: 39639556
Works perfectly! Thanks!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

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…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

689 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