what s for

  • Thread starter Jean Pierre Daviau
  • Start date
J

Jean Pierre Daviau

Hi ,

I attempt to get a path from sendto and transform it in a url way. I want
call not to work with empty % variables
C:/ee$ert/\\ //wert\$4 56.tst = %1 %2 %3

-------------------------- start -----
:sub
SET _mypth=%_mypth% %i
::
FOR %%a IN (%1, %2, %3, %4, %5, %6, %7, %8, %9) DO IF EXIST %%a call :SUB
%%a
::
@echo "%_mypth:\=/%" | clip
------------------------ end --------------------
Thanks


Jean Pierre Daviau
 
B

billious

Jean Pierre Daviau said:
Hi ,

I attempt to get a path from sendto and transform it in a url way. I want
call not to work with empty % variables
C:/ee$ert/\\ //wert\$4 56.tst = %1 %2 %3

-------------------------- start -----
:sub
SET _mypth=%_mypth% %i
::
FOR %%a IN (%1, %2, %3, %4, %5, %6, %7, %8, %9) DO IF EXIST %%a call
:SUB %%a
::
@echo "%_mypth:\=/%" | clip
------------------------ end --------------------
Thanks


Jean Pierre Daviau

This solution developed using XP
It may work for NT4/2K

----- batch begins -------
[1]@echo off
[2]set _mypth=
[3]call :sub c:/ee$ert//\ //wert\$4 56.tst
[4]echo final _mypth is %_mypth%
[5]echo or _mypth is %_mypth:\=/%
[6]set _mypth=
[7]goto :eof
[8]
[9]:sub
[10]if [%1]==[] goto :eof
[11]echo adding %1
[12]set _mypth=%_mypth% %1
[13]shift
[14]goto sub
------ batch ends --------

Lines start [number] - any lines not starting [number] have been wrapped and
should be rejoined. The [number] that starts the line should be removed

The label :eof is defined in NT+ to be end-of-file but MUST be expressed as
:eof

Perhaps you should read alt.msdos.batch.nt - lots of prior discussion on
various techniques, and read the FAQ there - pointer posted every Monday.
 
F

foxidrive

Hi ,

I attempt to get a path from sendto and transform it in a url way. I want
call not to work with empty % variables
C:/ee$ert/\\ //wert\$4 56.tst = %1 %2 %3

-------------------------- start -----
:sub
SET _mypth=%_mypth% %i
::
FOR %%a IN (%1, %2, %3, %4, %5, %6, %7, %8, %9) DO IF EXIST %%a call :SUB
%%a
::
@echo "%_mypth:\=/%" | clip
------------------------ end --------------------
Thanks

I'm not sure that I understand but to stop the call you could use:

if not "%%a"=="" call :SUB %%a
 
J

Jean Pierre Daviau

Hi,
¨>if not "%%a"=="" call :SUB %%a
creates an infinite loop.

Where should I put the sub for the script to finish properly?



----------- forwSlashes.cmd -------------------
FOR %%a IN (%1, %2, %3, %4, %5, %6, %7, %8, %9) DO call :sub %%a
@echo "%_mypth:\=/%"

:sub
IF %i=={} goto :eof
SET _mypth=%_mypth% %i


-------------------- end ---------------------------------

Calling the batch on the command line:

at the prompt¨>>forwSlashes.cmd C:\ee$ert// \\wert/$4 56.tst

JPD
 
J

Jean Pierre Daviau

billious said:
Jean Pierre Daviau said:
Hi ,

I attempt to get a path from sendto and transform it in a url way. I
want call not to work with empty % variables
C:/ee$ert/\\ //wert\$4 56.tst = %1 %2 %3

-------------------------- start -----
:sub
SET _mypth=%_mypth% %i
::
FOR %%a IN (%1, %2, %3, %4, %5, %6, %7, %8, %9) DO IF EXIST %%a call
:SUB %%a
::
@echo "%_mypth:\=/%" | clip
------------------------ end --------------------
Thanks


Jean Pierre Daviau

This solution developed using XP
It may work for NT4/2K

----- batch begins -------
[1]@echo off
[2]set _mypth=
[3]call :sub c:/ee$ert//\ //wert\$4 56.tst
[4]echo final _mypth is %_mypth%
[5]echo or _mypth is %_mypth:\=/%
[6]set _mypth=
[7]goto :eof
[8]
[9]:sub
[10]if [%1]==[] goto :eof
[11]echo adding %1
[12]set _mypth=%_mypth% %1
[13]shift
[14]goto sub
------ batch ends --------

It does work like that
set _mypth=
set _pth=%1, %2, %3, %4, %5, %6, %7, %8, %9
call :sub %_pth%

etc

I would like to see the for command work too.

To understand cmd a bit more I think . . .
 
J

Jean Pierre Daviau

Another thing
----------- forwSlashes.cmd -------------------
FOR %%a IN (%1, %2, %3, %4, %5, %6, %7, %8, %9) DO call :sub %%a
@echo "%_mypth:\=/%"

:sub
IF %i=={} goto :eof
SET _mypth=%_mypth% %i


-------------------- end ---------------------------------

It gives a white space at the beginning of the path

" C:/Users/Jean Pierre/Desktop/emailsCours.txt"

so I try:

@echo off
set _mypth=
set _pth= %1,%2,%3,%4,%5,%6,%7,%8,%9
call :sub %_pth%
shift
call :sub2 %_pth%
set _mypth=%_mypth:\=/%
@echo "%_mypth%" | clip
set _mypth=
goto :eof
::
:sub
if [%1]==[] goto :eof
set _mypth=%_mypth%%1
::
:sub2
if [%1]==[] goto :eof
set _mypth=%_mypth% %1
shift
goto sub2
 
J

Jean Pierre Daviau

The following works. But I still would prefer my for command line :blush:)
-------------------------- ---------------
@echo off
set _mypth=
set _pth= %1,%2,%3,%4,%5,%6,%7,%8,%9
call :sub %_pth%
::
set _mypth=%_mypth:\=/%
@echo "%_mypth%"
set _mypth=
goto :eof
::
:sub
if [%1]==[] goto :eof
set _mypth=%_mypth%%1
shift
::
:sub2
if [%1]==[] goto :eof
set _mypth=%_mypth% %1
shift
goto sub2
--------------------------------
 
J

Jean Pierre Daviau

Jean Pierre Daviau said:
The following works. But I still would prefer my for command line :blush:)

Do I get it?
-------------------------- ---------------
set _mypth=
::
for %%a in (%1,%2,%3,%4,%5,%6,%7,%8,%9) do call :sub %%a
@echo "%_mypth:\=/%" | clip
set _mypth=
goto :end
::
:sub
set _mypth=%_mypth%%1
goto :eof
:end
 
J

Jean Pierre Daviau

Jean Pierre Daviau said:
Do I get it?
-------------------------- a33.cmd ---------------
set _mypth=
::
for %%a in (%1,%2,%3,%4,%5,%6,%7,%8,%9) do call :sub %%a
@echo "%_mypth:\=/%" set _mypth=
goto :end
::
:sub
set _mypth=%_mypth%%1
goto :eof
:end

The for loops does not work.

a33.cmd C:\Program Files (x86)\Expert Guide for Windows

Expert was unattended
 
J

Jean Pierre Daviau

Jean Pierre Daviau said:
The for loops does not work.

a33.cmd C:\Program Files (x86)\Expert Guide for Windows

Expert was unattended

This works but I am still not satisfied.


a33.cmd "C:\Program Files (x86)\Expert Guide for Windows"
 
T

T Lavedas

"Jean Pierre Daviau" <[email protected]> a crit dans le message de






This works but I am still not satisfied.

a33.cmd   "C:\Program Files (x86)\Expert Guide for Windows"

You can try using the %* argument, instead of %1 - as in ...

@echo off
set _mypth=%*
echo."%_mypth:\=/%" | clip

Then the quotes aren't required - though this assumes only one
argument is desired.

Tom Lavedas
***********
http://there.is.no.more/tglbatch/
 
J

Jean Pierre Daviau

"T Lavedas" <[email protected]> a écrit dans le message de
"Jean Pierre Daviau" <[email protected]> a crit dans le message
de






This works but I am still not satisfied.

a33.cmd "C:\Program Files (x86)\Expert Guide for Windows"

You can try using the %* argument, instead of %1 - as in ...

@echo off
set _mypth=%*
echo."%_mypth:\=/%" | clip

Then the quotes aren't required - though this assumes only one
argument is desired.

Tom Lavedas
***********


The path has white spaces interpreted has arguments.

On the other hand when one's uses right clic sendto to the batch 'sendto'
encloses the path in double quotes automatically.
 
T

T Lavedas

"T Lavedas" <[email protected]> a écrit dans le message de



You can try using the %* argument, instead of %1 - as in ...

@echo off
  set _mypth=%*
  echo."%_mypth:\=/%" | clip

Then the quotes aren't required - though this assumes only one
argument is desired.

Tom Lavedas
***********

The path has  white spaces interpreted has arguments.

On the other hand when one's uses right clic sendto  to the batch 'sendto'
encloses the path in double quotes automatically.

From the help for the CALL statement:

In addition, expansion of batch script argument references (%0, %1,
etc.) have been changed as follows:

%* in a batch script refers to all the arguments (e.g. %1 %2 %3
%4 %5 ...)

That is, when used the spaces (and other delimiters) are replicated
exactly as they are on the command line - all except any trailing
spaces.

For example, this one line test procedure illustrates the point ...

@echo [%*]

When saved as qt.cmd and run, with examples ...

C: Testing>qt one two;three
[one two;three]

C: Testing>qt one two; three
[one two; three]

C: Testing>

Tom Lavedas
=========
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top