Batch file - Copying items from one UNC to another

Monopoly money comes in many flavors: 7, Vista, XP, 2K, ME, 98, etc.

Moderators: Flying Fox, Ryu Connor

Batch file - Copying items from one UNC to another

Postposted on Thu Apr 21, 2011 1:05 pm

I need some help creating a batch file that will do the following, I'm not sure what syntax I should be using.

The idea is to copy a folder and it's contents from a variable network location to another network location. What I would like is to be prompted to enter the computer name and then have it copy the stuff I need to the network location.

My flawed logic goes something like this:

1) Run batch file
2) Prompt user for computer hostname
3) Use hostname as a variable when running next command which copies the contents to a fixed network location
4) Fin

EDIT: on second thought it's probably easier to just say what I need done instead of being so vague so here goes: We're upgrading to Win7 and I need to copy the Favorites folder from the users old XP PC's to their home folders on the network. So there's permissions involved, UNC paths and stuff like that so it would be great to run a batch file which will prompt me to enter in the users old XP hostname, copy the Favorites folder and paste it into their home folder on the network.
-Playing shooters on a console is like doing brain surgery with an ice-cream scoop-
Jon
Gerbil Elite
 
Posts: 964
Joined: Sat Feb 14, 2004 7:44 pm
Location: -Canada-

Re: Batch file - Copying items from one UNC to another

Postposted on Thu Apr 21, 2011 3:24 pm

Doesn't Microsoft's User State Migration Toolkit do this for you?
FakeAlGore
Gerbil
 
Posts: 44
Joined: Fri Apr 15, 2011 12:23 pm
Location: Garland, TX - USA

Re: Batch file - Copying items from one UNC to another

Postposted on Thu Apr 21, 2011 3:36 pm

Follow Al's suggestion.
"Welcome back my friends to the show that never ends. We're so glad you could attend. Come inside! Come inside!"
Ryu Connor
Global Moderator
Gold subscriber
 
 
Posts: 3537
Joined: Thu Dec 27, 2001 7:00 pm
Location: Marietta, GA

Re: Batch file - Copying items from one UNC to another

Postposted on Fri Apr 22, 2011 12:18 am

Prompting pretty much means batch files is a no-go. You can do that with PowerShell though, or other language such as VBScript (oh the horror!).

But yes, if there is a OS feature that can do what you want, it is always better.
Image
The Model M is not for the faint of heart. You either like them or hate them.

Gerbils unite! Fold for UnitedGerbilNation, team 2630.
Flying Fox
Gerbil God
 
Posts: 24411
Joined: Mon May 24, 2004 2:19 am

Re: Batch file - Copying items from one UNC to another

Postposted on Fri Apr 22, 2011 12:38 am

You can always have a command line argument of the hostname.. I assume that if the user is typing a hostname, they know enough to be running the command from a CLI..
druidcent
Minister of Gerbil Affairs
 
Posts: 2077
Joined: Wed Aug 07, 2002 7:55 pm
Location: Earth, Sol, Milky Way

Re: Batch file - Copying items from one UNC to another

Postposted on Fri Apr 22, 2011 2:18 am

http://www.robvanderwoude.com/userinput.php

There are other ways, but this looks promising.
Jason181
Gerbil First Class
Silver subscriber
 
 
Posts: 181
Joined: Thu May 19, 2005 7:23 pm
Location: Oregon

Re: Batch file - Copying items from one UNC to another

Postposted on Fri Apr 22, 2011 7:19 am

Code: Select all
Sub Main()       
        Dim cmds As String() = Environment.GetCommandLineArgs
        Dim myVar1= cmds(1)     
        Dim myVar2= cmds(2) 
        ' Code to copy files around below
    End Sub


Then the .exe could have something like "-UNCPath1 -UNCPath2" etc. It creates an array of strings that represent each parameter you pass. Just my .02
Corsair 600T | ASUS P8P67 PRO | Intel 2500k @ 4.4Ghz | EVGA 560 TI | G.SKILL Ripjaws Series 8GB | Corsair HX650 650W
steelcity_ballin
Gerbilus Supremus
Silver subscriber
 
 
Posts: 11913
Joined: Mon May 26, 2003 5:55 am
Location: Pittsburgh PA

Re: Batch file - Copying items from one UNC to another

Postposted on Wed Apr 27, 2011 1:36 pm

I figured it out shortly after posting, pretty simple:

Code: Select all
SET /P COMPNAME=Enter PC name to copy 'Favorites' FROM:
SET /P USRNAME=Enter the Username of the user, CHECK SPELLING:
XCOPY /Y /E "\\%COMPNAME%\c$\Documents and Settings\%USRNAME%\Favorites" "H:\Favorites"


So this prompts me for the computer name and the user name and then does all the dirty work.
-Playing shooters on a console is like doing brain surgery with an ice-cream scoop-
Jon
Gerbil Elite
 
Posts: 964
Joined: Sat Feb 14, 2004 7:44 pm
Location: -Canada-

Re: Batch file - Copying items from one UNC to another

Postposted on Tue Jun 28, 2011 11:41 am

I know this is a little after the fact, but rather than xcopy, you might be interested in Robocopy.
Jason181
Gerbil First Class
Silver subscriber
 
 
Posts: 181
Joined: Thu May 19, 2005 7:23 pm
Location: Oregon


Return to Windows

Who is online

Users browsing this forum: No registered users and 2 guests