Personal computing discussed

Moderators: renee, Flying Fox, Ryu Connor

 
Jon
Gerbil Elite
Topic Author
Posts: 980
Joined: Sat Feb 14, 2004 7:44 pm
Location: -Alberta-

Batch file - Copying items from one UNC to another

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.
Image
-Playing shooters on a console is like doing brain surgery with an ice-cream scoop-
 
FakeAlGore
Gerbil
Posts: 44
Joined: Fri Apr 15, 2011 12:23 pm

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

Thu Apr 21, 2011 3:24 pm

Doesn't Microsoft's User State Migration Toolkit do this for you?
 
Ryu Connor
Global Moderator
Posts: 4369
Joined: Thu Dec 27, 2001 7:00 pm
Location: Marietta, GA
Contact:

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

Thu Apr 21, 2011 3:36 pm

Follow Al's suggestion.
All of my written content here on TR does not represent or reflect the views of my employer or any reasonable human being. All content and actions are my own.
 
Flying Fox
Gerbil God
Posts: 25690
Joined: Mon May 24, 2004 2:19 am
Contact:

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

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.
The Model M is not for the faint of heart. You either like them or hate them.

Gerbils unite! Fold for UnitedGerbilNation, team 2630.
 
druidcent
Minister of Gerbil Affairs
Posts: 2510
Joined: Wed Aug 07, 2002 7:55 pm
Location: Earth, Sol, Milky Way
Contact:

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

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..
 
Jason181
Gerbil First Class
Posts: 186
Joined: Thu May 19, 2005 7:23 pm
Location: Oregon

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

Fri Apr 22, 2011 2:18 am

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

There are other ways, but this looks promising.
 
steelcity_ballin
Gerbilus Supremus
Posts: 12072
Joined: Mon May 26, 2003 5:55 am
Location: Pittsburgh PA

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

Fri Apr 22, 2011 7:19 am

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
 
Jon
Gerbil Elite
Topic Author
Posts: 980
Joined: Sat Feb 14, 2004 7:44 pm
Location: -Alberta-

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

Wed Apr 27, 2011 1:36 pm

I figured it out shortly after posting, pretty simple:

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.
Image
-Playing shooters on a console is like doing brain surgery with an ice-cream scoop-
 
Jason181
Gerbil First Class
Posts: 186
Joined: Thu May 19, 2005 7:23 pm
Location: Oregon

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

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.

Who is online

Users browsing this forum: No registered users and 1 guest
GZIP: On