Script to move files into corresponding folders based on file name.

I am trying to create a script that will allow me to move files from one directory to another. I have hundreds of files within a directory under '\\abcdcfile\Operations\Statements To Print\08301015'  with names like 'RobertJames30aSEP15.pdf', I need a script that will move these files to '\\abcapp\c$\Consultant\Abcap files\Consultant\Portfolio Folders\30a\2015'. The 30a within the filename is what identifies which folder the file must be moved into.  

Any help is appreciated.
nicconnectAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NVITCommented:
This should help. Make a .bat of this code.
Open a CMD window to run it:
@echo off
setlocal enabledelayedexpansion

set SrcDir=\\abcdcfile\Operations\Statements To Print\08301015
set TgtRoot=\\abcapp\c$\Consultant\Abcap files\Consultant\Portfolio Folders

pushd %SrcDir%
for %%a in (*) do (
  set FName=%%a
  set Tail=!FName:~-12!
  set Folder=!Tail:~0,3!
  set MMM=!Tail:~3,3!
  set YY=!Tail:~6,2!
  set TgtDir=%TgtRoot%\!Folder!\20!YY!
  xcopy /y /i "!FName!" "!TgtDir!\"
)

popd

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.