This seemingly simple task stumps and trips up a lot of people in both ConfigMgr 2007 and ConfigMgr 2012. It’s not that it’s a difficult task per se, it’s that people go into it with bad assumptions.
The main bad assumption has to do with the current working directory. I discussed this previously (Current Directory in ConfigMgr Programs) but in summary and in general, the current working directory of a program in ConfigMgr is the folder containing the package files whether that be cached locally or on the DP based on where the program is run from. You should never count on it being in one place and thus you should never hard-code a path in. Using a batch file though, you can use the %~dp0 batch file parameter within the batch file itself to refer to the directory the batch file is run from.
The very simple solution presented here can of course be expanded upon and customized but is flexible enough to be just dropped in without any real customization.
1. Create a parent folder in your source file repository.
2. Create a sub-folder in the folder just created called Files2Copy and place the files you are going to copy in this folder.
4. Create a batch file called filecopy.bat with the below two lines and place it in the parent directory created in step 1. This batch file will create a folder specified on the command-line (if it doesn’t already exist) and copy the files from the Files2Copy folder into it.
if not exist "%~1" md "%~1" copy /y "%~dp0Files2Copy\*.*" "%~1"
5. Create a package using the parent directory created in step 1 as the source file location.
6. Create a program and set the command line to
Note that although my source directory and destination directory are both named “Desktop Tools”, this was just a convenient naming standard I adopted for this example and does not have to be the case.
7. Advertise/Deploy the program to the desired systems.
You can of course modify this very simple batch file to do some more complex things or use xcopy (http://technet.microsoft.com/en-us/library/bb491035.aspx) to perform advanced filtering and selective copying of files and sub-folders.