Batch files.. is this possible! (passing in argument)
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
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.
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?
Still cant see how it is going to be done.... seems a very dirty way to do it!
Any suggestions?
Lets see...
Might not be exactly correct, but you should get the idea
@echo offrem ** setup local variablesSET DIRECTORY=%1SET NEW_DIRECTORY=NewDirectoryNamerem ** check new directory existsif not exist %NEW_DIRECTORY% mkdir %NEW_DIRECTORY%rem ** copy all files overxcopy /E %DIRECTORY% %NEW_DIRECTORY%rem ** delete all files from old directorydel /s %DIRECTORY%\*.*rmdir %DIRECTORY%rem ** clear variablesSET DIRECTORY=SET NEW_DIRECTORY=@echo on
Might not be exactly correct, but you should get the idea
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
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
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
Yeap that seems like the only option!
Will try it from LUA as dont want to mess with original code just Yet!
Thanks
Will try it from LUA as dont want to mess with original code just Yet!
Thanks
Sure, you can parse arguments in batch files: watch
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]
@echo offrem **Example argument parser:Parserem ** Check the 1st argument on list (updated later with shift command)if "%1"=="" goto Completeif "%1"=="-s" goto Silentif "%1"=="-v" goto Versionif "%1"=="-f" goto Foorem ** other arguments not processedecho %1 not parsed!, continuing to next argumentshiftgoto Parse:Silentecho Going to Silent Mode! (does nothing really)Shiftgoto Parse:Versionrem ** Shift past -v argumentShiftrem ** next argument is versionset VERSION=%1echo %VERSION% is new versionrem ** go to next argumentShiftgoto Parse:Fooecho FooBared!Shiftgoto Parse:Completeecho 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]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement