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


How do I Copy Files to Folders with Same Name?

Posted on 2008-06-16
Medium Priority
Last Modified: 2010-04-21
I have a need to move all of our users .pst files following an ExMerge from Exchange, into an existing folderstructure with permissions already set.  The source folder has all the username.pst files in one directory.  The destination folder has an existing folders based on the username.  

Example...I am looking for an automated method to move the C:\pst\Joe.Smith.pst to D:\users\Joe.Smith

Question by:makurz
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

Assisted Solution

BasiKobrA earned 240 total points
ID: 21800247

Something like this should do it.
@echo off
set SOURCEFOLDER=C:\Documents and Settings\source
set DESTINATIONFOLDER=C:\Documents and Settings\users
for /f "delims=. tokens=1,2" %%A in ('dir /b "%SOURCEFOLDER%"') do (
	if "%%B"=="pst" move "%SOURCEFOLDER%\%%A.%%B"  "%DESTINATIONFOLDER%\%%A\."

Open in new window

LVL 33

Accepted Solution

knightEknight earned 260 total points
ID: 21802805
BasiKobrA, I think using a . as a delimiter may cause you problems because the filenames contain those characters.  I have modified your script to account for this:

@echo off
set SOURCEFOLDER=C:\Documents and Settings\source
set DESTINATIONFOLDER=C:\Documents and Settings\users
for /f  %%A in ('dir /b "%SOURCEFOLDER%\*.pst"') do (
   move "%SOURCEFOLDER%\%%~nA.pst"  "%DESTINATIONFOLDER%\%%~nA\."

Expert Comment

ID: 21802894
True, didn't think of that.

Author Closing Comment

ID: 31467861
BasiKobrAand knightEknight, Thanks for the Quick Reply. You saved me from lots of work!

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article will help to fix the below errors for MS Exchange Server 2013 I. Certificate error "name on the security certificate is invalid or does not match the name of the site" II. Out of Office not working III. Make Internal URLs and Externa…
Check out this step-by-step guide for using the newly updated Experts Exchange mobile app—released on May 30.
In this video we show how to create an Address List in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Organization >> Ad…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

670 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