Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How do I Copy Files to Folders with Same Name?

Posted on 2008-06-16
4
Medium Priority
?
337 Views
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

Thanks
0
Comment
Question by:makurz
  • 2
4 Comments
 
LVL 4

Assisted Solution

by:BasiKobrA
BasiKobrA earned 240 total points
ID: 21800247
Hey,

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

0
 
LVL 33

Accepted Solution

by:
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\."
)  
0
 
LVL 4

Expert Comment

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

Author Closing Comment

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

Featured Post

[Webinar] Cloud Security

In this webinar you will learn:

-Why existing firewall and DMZ architectures are not suited for securing cloud applications
-How to make your enterprise “Cloud Ready”, and fix your aging DMZ architecture
-How to transform your enterprise and become a Cloud Enabler

Question has a verified solution.

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

How to effectively resolve the number one email related issue received by helpdesks.
Steps to fix error: “Couldn’t mount the database that you specified. Specified database: HU-DB; Error code: An Active Manager operation fail”
In this video we show how to create an email address policy 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 Mail Flow…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Suggested Courses

963 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