Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

batch to move folders based on folder name

Posted on 2013-11-11
2
Medium Priority
?
818 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 2000 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

721 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