Click to See Complete Forum and Search --> : Simple batch (.bat) file question


nick9871
July 24th, 2007, 01:48 PM
Not sure if this is the right forum for this question.

I need to create a simple .bat file that when run copies the contents of a directory (and subdirectories) , to a new folder somewhere else. The key issue here is that I would like the batch file to copy the contents to a created folder with the name of its current folder.

Example:

batch file lies in:

C:\stuff\%variable%\createnewcommon.bat

I want to be able to run the batch file and have it do this:

copy contents of C:\morestuff\common to C:\morestuff\%variable%

The %variable% directory name will change because I have multiple directories that I will do this with.

Right now, the only way I can figure out how to do this is to use the %0 variable and then name the .bat file accordingly. But I would like this to be dynamic and based off of the directory name.

@ECHO off
rem This program copies the exsisting ATMEL common folder to a specified folder
rem The program will then delete the ATMEL common folder so it can be re-hardlinked

@ECHO on
echo This program will allow you to create a copy of the current ATMEL
echo common folder and will save it as a folder under the COMMON
echo directory with the echo name of the current PLATFORM folder.
@ECHO off


xcopy C:\COMMON\SRC\SOC\ATMEL C:\COMMON\SRC\SOC\%0 /I /T /E /H
xcopy C:\COMMON\SRC\SOC\ATMEL C:\COMMON\SRC\SOC\%0 /I /E /H
rmdir C:\COMMON\SRC\SOC\ATMEL /S

PeejAvery
July 24th, 2007, 02:37 PM
[ moved ]

dglienna
July 24th, 2007, 11:07 PM
Can't use XCOPY, I'd guess
Use a FOR loop;

http://www.easydos.com/for.html