Solved

batch to move folders based on folder name

Posted on 2013-11-11
2
748 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
2 Comments
 
LVL 82

Accepted Solution

by:
oBdA earned 500 total points
Comment Utility
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
Comment Utility
Works perfectly! Thanks!
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

I have published numerous articles here at Experts Exchange that present programs/scripts written in a language called AutoHotkey. Each of those articles has a brief paragraph describing where to download the product and how to install it. I have al…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

743 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

7 Experts available now in Live!

Get 1:1 Help Now