Solved

batch to move folders based on folder name

Posted on 2013-11-11
2
779 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 84

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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

One of my most closely kept secrets is revealed in this discussion How to output text on the same line This question was recently posted in EE by Simon336697 (http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_2459…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

766 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