Click to See Complete Forum and Search --> : XCOPY commands


ctgreen
August 13th, 2009, 09:59 PM
Hey there. First off, great site!

I am in no means a programmer so that's why I need your expertise.

I am trying to help my manager out with setting up a batch file that copies the users profile desktop and favorites folders into the users home drive (H:); which is a network share.

I have done some research and gathered the coding for it, however, I am missing something because it doesn't seem to work.

@echo off
REM copy desktop
xcopy "C:\Documents and Settings\%userprofile%\Desktop\*.*" H:\Desktop\ /c /s /r /d /y /i > H:\Desktop\xcopy.log
REM copy favorites
xcopy "C:\Documents and Settings\%userprofile%\Favorites\Links\*.*" H:\Favorites\ /c /s /r /d /y /i > H:\Favorites\xcopy.log


I know this is probably very basis for you guys but this is way over my head.

Thanks in advance.

dglienna
August 13th, 2009, 11:23 PM
Look up Powershell 2.0 CTP.

Here's a script. You can filter what you want, copy it (with permission), and even execute scripts remotely, to push the data to you in a batch file.


# ##
# # Start of Script
# ##
#
# # Get the list of special folders
# $folders = [system.Enum]::GetValues([System.Environment+SpecialFolder])
#
# # Display these folders
# "Folder Name Path"
# "----------- -----------------------------------------------"
# foreach ($folder in $folders) {
# "{0,-22} {1,-15}" -f $folder,[System.Environment]::GetFolderPath($folder)
# }
# #End of Script

# -----------------------------------------------
# Desktop C:\Users\tfl\Desktop
# Programs C:\Users\tfl\AppData\Roaming\Microsoft\Windows\Start Menu\Programs
# Personal C:\Users\tfl\Documents
# Personal C:\Users\tfl\Documents
# Favorites C:\Users\tfl\NetHood\Favorites
# Startup C:\Users\tfl\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
# Recent C:\Users\tfl\AppData\Roaming\Microsoft\Windows\Recent
# SendTo C:\Users\tfl\AppData\Roaming\Microsoft\Windows\SendTo
# StartMenu C:\Users\tfl\AppData\Roaming\Microsoft\Windows\Start Menu
# MyMusic C:\Users\tfl\Music
# DesktopDirectory C:\Users\tfl\Desktop
# MyComputer
# Templates C:\Users\tfl\AppData\Roaming\Microsoft\Windows\Templates
# ApplicationData C:\Users\tfl\AppData\Roaming
# LocalApplicationData C:\Users\tfl\AppData\Local
# InternetCache C:\Users\tfl\AppData\Local\Microsoft\Windows\Temporary Internet Files
# Cookies C:\Users\tfl\AppData\Roaming\Microsoft\Windows\Cookies
# History C:\Users\tfl\AppData\Local\Microsoft\Windows\History
# CommonApplicationData C:\ProgramData
# System C:\Windows\system32
# ProgramFiles C:\Program Files (x86)
# MyPictures C:\Users\tfl\Pictures
# CommonProgramFiles C:\Program Files (x86)\Common Files

the_cat
August 14th, 2009, 06:50 AM
You've used the environment variable %userprofile% which, if your name is CTGREEN and your profile is on the C: drive (and you're using an English o/s) would return:
C:\Documents And Settings\CTGREEN
Therefore you can miss out the path "C:\Documents and Settings\" in your XCOPY, so rewrite it as (I took the trailing backslash off the destination folder too):

@echo off
REM copy desktop
xcopy "%userprofile%\Desktop\*.*" H:\Desktop /c /s /r /d /y /i > H:\Desktop\xcopy.log
REM copy favorites
xcopy "%userprofile%\Favorites\Links\*.*" H:\Favorites /c /s /r /d /y /i > H:\Favorites\xcopy.log

Or, slightly better, write it as:

@echo off
REM copy desktop
if not exist H:\Desktop MD H:\Desktop
xcopy "%userprofile%\Desktop\*.*" H:\Desktop /c /s /r /d /y /i > H:\Desktop\xcopy.log
REM copy favorites
if not exist H:\Favorites MD H:\Favorites
xcopy "%userprofile%\Favorites\Links\*.*" H:\Favorites /c /s /r /d /y /i > H:\Favorites\xcopy.log

So the destination folder will be created in case it's not already there.

PeejAvery
August 14th, 2009, 07:52 AM
[ moved ]

ctgreen
August 15th, 2009, 12:22 AM
You've used the environment variable %userprofile% which, if your name is CTGREEN and your profile is on the C: drive (and you're using an English o/s) would return:
C:\Documents And Settings\CTGREEN
Therefore you can miss out the path "C:\Documents and Settings\" in your XCOPY, so rewrite it as (I took the trailing backslash off the destination folder too):

@echo off
REM copy desktop
xcopy "%userprofile%\Desktop\*.*" H:\Desktop /c /s /r /d /y /i > H:\Desktop\xcopy.log
REM copy favorites
xcopy "%userprofile%\Favorites\Links\*.*" H:\Favorites /c /s /r /d /y /i > H:\Favorites\xcopy.log

Or, slightly better, write it as:

@echo off
REM copy desktop
if not exist H:\Desktop MD H:\Desktop
xcopy "%userprofile%\Desktop\*.*" H:\Desktop /c /s /r /d /y /i > H:\Desktop\xcopy.log
REM copy favorites
if not exist H:\Favorites MD H:\Favorites
xcopy "%userprofile%\Favorites\Links\*.*" H:\Favorites /c /s /r /d /y /i > H:\Favorites\xcopy.log

So the destination folder will be created in case it's not already there.



The Cat! Thank you so much!!! It worked like a charm! :D