OK, this is slightly more difficult. Variables are passed into a batch file as command line parameters. An example of this would be the following:
Code:
Code for making a 'new' copy batch file - Filename: c:\copier.bat
@ECHO OFF
COPY %1 %2
This would be used as follows:
copier testfile.txt c:\folder
This would, in the same way as copy does, copy the file from c:\ to c:\folder\ by calling copy to do it. Not very helpful yet, but you can use this a bit better with a nested batch file.
File 1: test1.bat
Code:
@ECHO OFF
CALL test2.bat file.txt
ECHO.
ECHO The code here has now run
File2: test2.bat
Code:
@ECHO OFF
IF EXIST %1 (
DEL %1
) ELSE (
ECHO.
ECHO File does not exist
ECHO.
)
This would check to see if the file stored in batch file 1 exists, then if it does, deletes it, otherwise lets you know. After that, it returns to the first batch file where it left off. If you left out the CALL command it would go and run the second file then immidiately terminate without returning.
If you know BASIC, it equates to the CALL command is being a GOSUB with the end of the next file being a RETURN, whereas just the filename is a GOTO.
Hope this answers the question. If not, ask again and I'll try to solve it a bit better.
-EDIT
aah, it's been a while since I coded up a batch file. I must do this more often