Archived

This topic is now archived and is closed to further replies.

Burty

Batch files.. is this possible! (passing in argument)

Recommended Posts

I''m working on an app at the moment and need some help! I have an Accountancy App. It uses LUA scripts! This script will call a batch-file if a folder has not been updated after certain period of time! The batch file needs to copy the folder and all its subfolders, then create a folder and copy all the folders into it! It then must delete the original folder!! Also the name of the folder to copy will be supplied by the app! (as dont want any user input..so somehow need to pass an Argument to the batch file) Sorry if anything is not clear ! Thanks Brian

Share this post


Link to post
Share on other sites
In a batch file, you can access arguments with %1, %2, %3, etc. (it may start at %0, I don''t remember). To give the arguments, just call your batch file like a regular command.

Share this post


Link to post
Share on other sites
So .... say a LUA script could call the batch file and pass the directory to the batch file as an argument!...

Still cant see how it is going to be done.... seems a very dirty way to do it!

Any suggestions?

Share this post


Link to post
Share on other sites
Lets see...

  
@echo off
rem ** setup local variables
SET DIRECTORY=%1
SET NEW_DIRECTORY=NewDirectoryName

rem ** check new directory exists
if not exist %NEW_DIRECTORY% mkdir %NEW_DIRECTORY%

rem ** copy all files over
xcopy /E %DIRECTORY% %NEW_DIRECTORY%

rem ** delete all files from old directory
del /s %DIRECTORY%\*.*
rmdir %DIRECTORY%

rem ** clear variables
SET DIRECTORY=
SET NEW_DIRECTORY=
@echo on


Might not be exactly correct, but you should get the idea

Share this post


Link to post
Share on other sites
Ok i will ease off on the !!!!

So %1 is the first arugent after the batch file name.

Is there an ability to parse the arugment.. say break it up into two pieces...

Been going through Web tutorials and have not come across it yet.

Beernuts thats excelllent.. thats how i had in my mind to do it but afraid to try in case i failed

Thanks

Share this post


Link to post
Share on other sites
Instead of breaking any arguments up in the batch file, do that in the program(or LUA script or whatever) and pass the batch file 2 arguments. Access the first argument by %1 and the second by %2

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Yeap that seems like the only option!
Will try it from LUA as dont want to mess with original code just Yet!

Thanks

Share this post


Link to post
Share on other sites
Sure, you can parse arguments in batch files: watch



  
@echo off
rem **Example argument parser
:Parse
rem ** Check the 1st argument on list (updated later with shift command)
if "%1"=="" goto Complete
if "
%1"=="-s" goto Silent
if "
%1"=="-v" goto Version
if "
%1"=="-f" goto Foo
rem ** other arguments not processed
echo %1 not parsed!, continuing to next argument
shift
goto Parse

:Silent
echo Going to Silent Mode! (does nothing really)
Shift
goto Parse

:Version
rem ** Shift past -v argument
Shift
rem ** next argument is version
set VERSION=%1
echo %VERSION% is new version
rem ** go to next argument
Shift
goto Parse

:Foo
echo FooBared!
Shift
goto Parse

:Complete
echo Completed parsing tutorial. Bye!
@echo on



now type in any number of arguments, and it'll work ie
BatchFile -s
or
BatchFile -v 1.00 -s
or
Batchfile -f -s -v 1.00
or
Batchfile ff dff d dd d f ff -v 1.00 -f

Good stuff


[edited by - BeerNutts on May 9, 2003 10:17:00 AM]

Share this post


Link to post
Share on other sites
Ummmm!

Indeed that may work but there is more than 1 way to skin a cat!
Beernuts..thanks for your reply... excellent!

Share this post


Link to post
Share on other sites