Moving files in multiple directories to one folder via command line/script
Hi there,
I've been trying to make my life a little bit easier in regards to moving my clients .pst files around and have been trying to devise a way to move all .pst's within my C drive INCLUDING any within subdirectories (I set a few up in different locations
for testing) to a certain folder.
Currently the command I'm using is this: move C:\*.pst %userprofile%\Mail
Obviously that's moving any PST file within the root directory into the Mail folder. I'm sure there must be a switch/parameter that I'm missing that will include any PST's in the C drive subdirectories... But I'm not an expert with the command line... yet!
This will eventually go towards a script that I will roll out on each end user machine, but I'm sure I'll figure that part out.
Any advice would be much appreciated :@)
Pete
January 5th, 2011 8:46am
I would use robocopy.
Here's some switch info:
http://www.mydigitallife.info/2007/05/07/robocopy-syntax-command-line-switches-and-examples/
Test the /E or the /S switches.
Free Windows Admin Tool Kit Click here and download it now
January 5th, 2011 10:13am
The for command is your friend.
for /r c:\ %i in (*.pst) do move %i %userprofile%\Mail
January 5th, 2011 11:27am
That's pretty class JS2010, thanks! However I'm not sure I understand those commands, I'll have to do a bit of reading into that to get an idea of what that all means (unless you're willing to enlighten me?)
Problem is that some .PST's didn't move. For example I created three .pst's, called Move1, 2 and 3 and placed them in various folders on my C:/. As the command went along it hit some and said "The syntax of the command is incorrect.".. Which I thought
was odd as there's no special permissions on these folders.
Any ideas?
Free Windows Admin Tool Kit Click here and download it now
January 7th, 2011 7:55am
Maybe you have to quote it?
for /r c:\ %i in (*.pst) do move "%i" %userprofile%\Mail
January 7th, 2011 8:41am
You sir, are a king amongst men.
I have one more question, my plan here is to have all the files move at logon, into a folder which I intend to make with a batch file script also. The script I have made goes like this:
mkdir %userprofile%\Mail4
for /r c:\ %i in (*.pst) do move "%i" %userprofile%\Mail4
This only creates the Mail4 folder though... I've tried with & and && but this doesn't seem to make the second command run. Any thoughts?
Free Windows Admin Tool Kit Click here and download it now
January 10th, 2011 5:30am
Press return after the second line?
January 10th, 2011 6:15am
If this runs as a batch file the command screen opens for a split second, in which time it creates the folder. Second line isn't run.
Free Windows Admin Tool Kit Click here and download it now
January 10th, 2011 8:38am
FYI:
When you use this in a batchfile you have to use %%i instead of %i
so your logon.bat will contain this:
mkdir %userprofile%\Mail4
for /r c:\ %%i in (*.pst) do move "%%i" %userprofile%\Mail4
PS:
don't forget as well that %%i is case-sensitive and not the same as %%I (could be %%a or whatever as well)
July 1st, 2011 8:56am
xcopy is another vehicle worth considering
My MVP is for the Windows Desktop Experience, i.e. Windows XP, Vista and Windows 7 IT
Remote Assistance is available for a fee. Visit my IT site for information.
I am best with C++ and I am learning C# using Visual Studio 2010. My page on
Video Card Problems is now my most popular landing page. See my gaming site for game reviews etc.
Developer |
Windows IT | Chess |
Hardcore Games | Vegan Advocate |
PC Reviews
Free Windows Admin Tool Kit Click here and download it now
July 1st, 2011 9:22am