quoting

Oct 18, 2008
345
2
I was in the process of building batch files to copy files off old cd/dvd. I came across of file that as part of its name it contained “%20" in it — I have seen this were the %20 is a place holder for a space.

It was not clear to me how to “quote” this files name so the (tcc) copy command would not try to evaluate the %20. I tried changing the %20 to %%20 and ^%20 but both failed. Even tried the back-quote, but the file as passed to a subroutine via a “gosub” and I think that when the text got to the subroutine, the “%20" were now exposed again ----

Any pointers on how to do this would be appreciated – Thanks
 

Attachments

  • batchfile.txt
    467 bytes · Views: 43
May 20, 2008
11,865
121
Syracuse, NY, USA
Does this help?

Code:
v:\> type subr.btm
gosub foo1 `%%20`
gosub foo2 %%%%20
quit

:foo1 [name]
echo name = %name
return

:foo2 [name]
echo name = %name
return

v:\> subr.btm
name = %20
name = %20
 
Apr 2, 2011
1,553
13
55
North Carolina, USA
I don't have those folders / drives but what of: ?

>gosub cpy "e:\00optimized\pooh\pooh%%20sleeve%%20puppet%%2043640.jpg" "r:\cd-scrape\b6327aae22b51e7bb2470313f4a066b574e0283c\6a9cef80b5ab9d489a955d25f3b1fcb035334238.jpg"
 
May 20, 2008
11,865
121
Syracuse, NY, USA
File names probably don't have embedded variable references that you want expanded. So SETDOS /X-4 (disable nested variable expansion) might work well. Here's an example.


Code:
v:\> d *.test
2021-06-12  12:13               0  aa%20bb.test

v:\> type subr2.btm
setdos /x-4
do file in *.test
    echo name = %file
    gosub sub1 %file
enddo
setdos /x+4
quit

:sub1 [name]
echo name = %name
return

v:\> subr2.btm
name = aa%20bb.test
name = aa%20bb.test
 
Apr 2, 2011
1,553
13
55
North Carolina, USA
File names probably don't have embedded variable references that you want expanded. So SETDOS /X-4 (disable nested variable expansion) might work well. Here's an example.


Code:
v:\> d *.test
2021-06-12  12:13               0  aa%20bb.test

v:\> type subr2.btm
setdos /x-4
do file in *.test
    echo name = %file
    gosub sub1 %file
enddo
setdos /x+4
quit

:sub1 [name]
echo name = %name
return

v:\> subr2.btm
name = aa%20bb.test
name = aa%20bb.test

alias d=*dir /a /p /m /k /h /ne

correct Vince?