About call Function with Arguments

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Locked
Message
Author
goodywp
Posts: 250
Joined: 31 Jul 2017 09:57

About call Function with Arguments

#1 Post by goodywp » 28 Nov 2018 16:03

I just had a test about call function with arguments

Code: Select all

@echo off
echo.going to execute myDosFunc with different arguments

set fdl_1=function1
set fdl_2=function2
set fdl_3=function3

call:myDosFunc %fdl_1% *xt1.txt
call:myDosFunc %fdl_2% *xt2.txt
call:myDosFunc %fdl_3% *xt3.txt

goto:eof


::--------------------------------------------------------
::-- Function section starts below here
::--------------------------------------------------------

:myDosFunc    - here starts my function identified by it's label
cd C:\Users\test
if exist %~1 (
	cd %~1
	copy %~2 C:\Users\test\function\
	)

goto:eof
This above code works well and I got 3 .txt files copied to subfolder function

Now I use the similar code to do this following job and failed to do so, can not figure out why?

Code: Select all


set NAR_COMP_6=NAR KIA Tetra 0521
set NAR_COMP_7=NAR Applications
set NAR_COMP_8=NAR TSA Tetra 0521


call:convertFunc %NAR_COMP_6% *KIA.P3A
call:convertFunc %NAR_COMP_7% *852046.P3A
call:convertFunc %NAR_COMP_8% *TSA.P3A

goto:eof

::--------------------------------------------------------
::-- Function section starts below here
::--------------------------------------------------------


:convertFunc    - here starts Convert function 
cd "%NEW_PACKAGE_BASE_PATH%\%NEW_PACKAGE_NAME%\%NEW_PKG_PART_NO%\Factory Download\TETRA\TELIUM3"

if exist %~1 (
	cd %~1
	copy %~2 C:\auto_mockup_pkg\Tools\PACKAGER\
	)

goto:eof
Now the above code is not working... only thing different is

cd "%NEW_PACKAGE_BASE_PATH%\%NEW_PACKAGE_NAME%\%NEW_PKG_PART_NO%\Factory Download\TETRA\TELIUM3"

But I had variable input for all the %NEW_PACKAGE_BASE_PATH%\%NEW_PACKAGE_NAME%\%NEW_PKG_PART_NO%\Factory Download\TETRA\TELIUM3
After run, prompt to %NEW_PACKAGE_BASE_PATH%\%NEW_PACKAGE_NAME%\%NEW_PKG_PART_NO%\Factory Download\TETRA\TELIUM3 that mean cd is working correctly
But nothing happened...
when I comment out if exist %~1 (
it complain
The system cannot find the path specified. (for cd %~1)
The system cannot find the file specified.. (for copy %~2 C:\auto_mockup_pkg\Tools\PACKAGER\)

Physically checked the folders are there and files too, Any reason why I can not do it ...
Thanks

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: About call Function with Arguments

#2 Post by Squashman » 28 Nov 2018 16:30

When file and folder names have spaces in them, what are you supposed to do?

goodywp
Posts: 250
Joined: 31 Jul 2017 09:57

Re: About call Function with Arguments

#3 Post by goodywp » 29 Nov 2018 04:49

Squashman wrote:
28 Nov 2018 16:30
When file and folder names have spaces in them, what are you supposed to do?
OOPS again the space forgot to take care of.. My bad..
Should I delete this post, please advise...
Thanks

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: About call Function with Arguments

#4 Post by Ed Dyreen » 30 Nov 2018 10:42

goodywp wrote:
29 Nov 2018 04:49
OOPS again the space forgot to take care of.. My bad..
Should I delete this post, please advise...
Thanks
Yes, I would appreciate that :mrgreen:

Locked