Batch File Parameters

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

What is the maximum number of parameters that can be passed to a batch
command? I get a strange error message if I use more than about 20. If that
is the limit, can it be raised.

Thanks
ROGER
 
Roger said:
What is the maximum number of parameters that can be passed to a batch
command? I get a strange error message if I use more than about 20. If that
is the limit, can it be raised.

Thanks
ROGER

It would be helpful if you could quote the "strange error" you
observe so that we don't have to guess what your problem
might be. Regardless of this, I ran the batch file below and
it worked perfectly well with 35 parameters.

@echo off
set count=1
:again
echo Parm%count%=%1
set /a count=%count%+1
shift
pause
if %count% LEQ 35 goto again
 
The Message appears in a window titled with the name of the batch file:
Windows cannot access the specified device, path, or file. You may not
have the appropriate permissions to access the item.

Thans again,
Roger
 
Fine, now let's have a look at your batch file!


Roger said:
The Message appears in a window titled with the name of the batch file:
Windows cannot access the specified device, path, or file. You may not
have the appropriate permissions to access the item.

Thans again,
Roger
 
OK, Here it is. I works for 25 parameters but fails with 26!
-----------------------------------------------------------------------------------------------
@echo off
echo Archive Routine vF.0

:DOMOVE
set Source=%1

set Name=%~n1
rem Name is the Folder name or filename w/o extension
set Short=%~sp1
rem Temp will be the path in short form
set TestDir=%Short:~1,7%
rem TestDir is the first 7 digits of the top path
rem It will be "DOCUME~" for "Documents and Settings"

:TESTSOURCE
if "%TestDir%"=="DOCUME~" GOTO CHCKATTR
Echo %Source% must be in "My Documents"
goto GETNEXT

:CHCKATTR
set Attrlist=%~a1
rem Attrlist is the attributes of the directory or file
set AttrFD=%Attrlist:~0,1%
rem AttrFD will be "d" for a directory or "-" for a file
echo %AttrFD%

:SETTARGET
set TarDir=%~dp1
rem TarDir is the full path of the folder containing the source
set Target=%TarDir:Documents and Settings=Archive%
rem Target is the target directory formed by replacing
rem "Documents and ..." with "ARCHIVE"

:MOVE
if not "%AttrFD%"=="d" goto MOVEIT
echo %source% is a directory
goto getnext
rem It's a File

:MOVEIT
xcopy /T /I %1 "%Target%"
rem This creates the directory structure
move /Y %1 "%Target%"
rem This will move a single file
if %errorlevel% EQU 0 GOTO OK
echo ARCHIVE NOT SUCCESSFUL code%errorlevel%f
GOTO END

:OK
echo . %Name%
echo . Successfully Archived to:
echo . %Target%

:GETNEXT
shift
if NOT [%1]==[] GOTO DOMOVE

:END
ECHO ARCHIVE finished
Pause
exit
 
I don't think your problem has anything to do with the
number of parameters. It is probably caused by one of
the following:
- The last parameter is not what you think it is. Add a trap
to your batch file so that every parameter gets echoed to
the screen.
- You may have exceeded the maximum total length of the
parameter string that cmd.exe can process. Maybe you're
running out of environment space. Again you can
verify this by echoing every parameter to the screen.

While your batch file uses a number of advanced features,
I wonder this is the best way to solve your problem. The
following fragment of a batch file would do much the same
as your own batch file but possibly in a more robust and
certainly in a more manageable way:

@echo off
if [%1]==[] goto :eof
:again
xxcopy /s /rc /yy %1 d:\Target\
shift
if not [%1]==[] goto again

I also wonder how you intend to enter 25 or more file names
to be archived. Sounds like a lot of typing! It would be easier
to use some suitable criterion, e.g. file date, archive attribute etc.

Roger said:
OK, Here it is. I works for 25 parameters but fails with 26!
-------------------------------------------------------------------------- ---------------------
@echo off
echo Archive Routine vF.0

:DOMOVE
set Source=%1

set Name=%~n1
rem Name is the Folder name or filename w/o extension
set Short=%~sp1
rem Temp will be the path in short form
set TestDir=%Short:~1,7%
rem TestDir is the first 7 digits of the top path
rem It will be "DOCUME~" for "Documents and Settings"

:TESTSOURCE
if "%TestDir%"=="DOCUME~" GOTO CHCKATTR
Echo %Source% must be in "My Documents"
goto GETNEXT

:CHCKATTR
set Attrlist=%~a1
rem Attrlist is the attributes of the directory or file
set AttrFD=%Attrlist:~0,1%
rem AttrFD will be "d" for a directory or "-" for a file
echo %AttrFD%

:SETTARGET
set TarDir=%~dp1
rem TarDir is the full path of the folder containing the source
set Target=%TarDir:Documents and Settings=Archive%
rem Target is the target directory formed by replacing
rem "Documents and ..." with "ARCHIVE"

:MOVE
if not "%AttrFD%"=="d" goto MOVEIT
echo %source% is a directory
goto getnext
rem It's a File

:MOVEIT
xcopy /T /I %1 "%Target%"
rem This creates the directory structure
move /Y %1 "%Target%"
rem This will move a single file
if %errorlevel% EQU 0 GOTO OK
echo ARCHIVE NOT SUCCESSFUL code%errorlevel%f
GOTO END

:OK
echo . %Name%
echo . Successfully Archived to:
echo . %Target%

:GETNEXT
shift
if NOT [%1]==[] GOTO DOMOVE

:END
ECHO ARCHIVE finished
Pause
exit
-------------------------------------------------------------------------- ---------------------
I execute it via a link on the sent to context menu. I can select files in
a folder in "My Documents" and move them to an Archive folder while
maintaining their directory structure!



Pegasus (MVP) said:
Fine, now let's have a look at your batch file!


20.
If
 
Pegasus,
Again thanks for your help! I am not typing in the file names. This is
being executed via a link in the "send to" menu. I can select files from a
list, right click, select "SEND TO" and select this batch file from that drop
down list. It should execute the fatch with all the selected file names as
parameters.

Also I am not familiar with the XXCOPY command. Where can I get Info on
it??? Remember I want to move the files not copy them!

Roger

Pegasus said:
I don't think your problem has anything to do with the
number of parameters. It is probably caused by one of
the following:
- The last parameter is not what you think it is. Add a trap
to your batch file so that every parameter gets echoed to
the screen.
- You may have exceeded the maximum total length of the
parameter string that cmd.exe can process. Maybe you're
running out of environment space. Again you can
verify this by echoing every parameter to the screen.

While your batch file uses a number of advanced features,
I wonder this is the best way to solve your problem. The
following fragment of a batch file would do much the same
as your own batch file but possibly in a more robust and
certainly in a more manageable way:

@echo off
if [%1]==[] goto :eof
:again
xxcopy /s /rc /yy %1 d:\Target\
shift
if not [%1]==[] goto again

I also wonder how you intend to enter 25 or more file names
to be archived. Sounds like a lot of typing! It would be easier
to use some suitable criterion, e.g. file date, archive attribute etc.

Roger said:
OK, Here it is. I works for 25 parameters but fails with 26!
-------------------------------------------------------------------------- ---------------------
@echo off
echo Archive Routine vF.0

:DOMOVE
set Source=%1

set Name=%~n1
rem Name is the Folder name or filename w/o extension
set Short=%~sp1
rem Temp will be the path in short form
set TestDir=%Short:~1,7%
rem TestDir is the first 7 digits of the top path
rem It will be "DOCUME~" for "Documents and Settings"

:TESTSOURCE
if "%TestDir%"=="DOCUME~" GOTO CHCKATTR
Echo %Source% must be in "My Documents"
goto GETNEXT

:CHCKATTR
set Attrlist=%~a1
rem Attrlist is the attributes of the directory or file
set AttrFD=%Attrlist:~0,1%
rem AttrFD will be "d" for a directory or "-" for a file
echo %AttrFD%

:SETTARGET
set TarDir=%~dp1
rem TarDir is the full path of the folder containing the source
set Target=%TarDir:Documents and Settings=Archive%
rem Target is the target directory formed by replacing
rem "Documents and ..." with "ARCHIVE"

:MOVE
if not "%AttrFD%"=="d" goto MOVEIT
echo %source% is a directory
goto getnext
rem It's a File

:MOVEIT
xcopy /T /I %1 "%Target%"
rem This creates the directory structure
move /Y %1 "%Target%"
rem This will move a single file
if %errorlevel% EQU 0 GOTO OK
echo ARCHIVE NOT SUCCESSFUL code%errorlevel%f
GOTO END

:OK
echo . %Name%
echo . Successfully Archived to:
echo . %Target%

:GETNEXT
shift
if NOT [%1]==[] GOTO DOMOVE

:END
ECHO ARCHIVE finished
Pause
exit
-------------------------------------------------------------------------- ---------------------
I execute it via a link on the sent to context menu. I can select files in
a folder in "My Documents" and move them to an Archive folder while
maintaining their directory structure!



Pegasus (MVP) said:
Fine, now let's have a look at your batch file!


The Message appears in a window titled with the name of the batch file:
Windows cannot access the specified device, path, or file. You may not
have the appropriate permissions to access the item.

Thans again,
Roger

:


What is the maximum number of parameters that can be passed to a batch
command? I get a strange error message if I use more than about 20.
If
that
is the limit, can it be raised.

Thanks
ROGER

It would be helpful if you could quote the "strange error" you
observe so that we don't have to guess what your problem
might be. Regardless of this, I ran the batch file below and
it worked perfectly well with 35 parameters.

@echo off
set count=1
:again
echo Parm%count%=%1
set /a count=%count%+1
shift
pause
if %count% LEQ 35 goto again
 
xxcopy.exe is a third-party utility that is far more versatile
than xcopy.exe. It has so many switches that you need
to run the command xxcopy /help > xxcopy.txt in order to
work out which one is best for you. In your case the /rc
switch is probably the right one: It deletes the source file(s)
after copy.


Roger said:
Pegasus,
Again thanks for your help! I am not typing in the file names. This is
being executed via a link in the "send to" menu. I can select files from a
list, right click, select "SEND TO" and select this batch file from that drop
down list. It should execute the fatch with all the selected file names as
parameters.

Also I am not familiar with the XXCOPY command. Where can I get Info on
it??? Remember I want to move the files not copy them!

Roger

Pegasus said:
I don't think your problem has anything to do with the
number of parameters. It is probably caused by one of
the following:
- The last parameter is not what you think it is. Add a trap
to your batch file so that every parameter gets echoed to
the screen.
- You may have exceeded the maximum total length of the
parameter string that cmd.exe can process. Maybe you're
running out of environment space. Again you can
verify this by echoing every parameter to the screen.

While your batch file uses a number of advanced features,
I wonder this is the best way to solve your problem. The
following fragment of a batch file would do much the same
as your own batch file but possibly in a more robust and
certainly in a more manageable way:

@echo off
if [%1]==[] goto :eof
:again
xxcopy /s /rc /yy %1 d:\Target\
shift
if not [%1]==[] goto again

I also wonder how you intend to enter 25 or more file names
to be archived. Sounds like a lot of typing! It would be easier
to use some suitable criterion, e.g. file date, archive attribute etc.

Roger said:
OK, Here it is. I works for 25 parameters but fails with 26!
--------------------------------------------------------------------------
---------------------
@echo off
echo Archive Routine vF.0

:DOMOVE
set Source=%1

set Name=%~n1
rem Name is the Folder name or filename w/o extension
set Short=%~sp1
rem Temp will be the path in short form
set TestDir=%Short:~1,7%
rem TestDir is the first 7 digits of the top path
rem It will be "DOCUME~" for "Documents and Settings"

:TESTSOURCE
if "%TestDir%"=="DOCUME~" GOTO CHCKATTR
Echo %Source% must be in "My Documents"
goto GETNEXT

:CHCKATTR
set Attrlist=%~a1
rem Attrlist is the attributes of the directory or file
set AttrFD=%Attrlist:~0,1%
rem AttrFD will be "d" for a directory or "-" for a file
echo %AttrFD%

:SETTARGET
set TarDir=%~dp1
rem TarDir is the full path of the folder containing the source
set Target=%TarDir:Documents and Settings=Archive%
rem Target is the target directory formed by replacing
rem "Documents and ..." with "ARCHIVE"

:MOVE
if not "%AttrFD%"=="d" goto MOVEIT
echo %source% is a directory
goto getnext
rem It's a File

:MOVEIT
xcopy /T /I %1 "%Target%"
rem This creates the directory structure
move /Y %1 "%Target%"
rem This will move a single file
if %errorlevel% EQU 0 GOTO OK
echo ARCHIVE NOT SUCCESSFUL code%errorlevel%f
GOTO END

:OK
echo . %Name%
echo . Successfully Archived to:
echo . %Target%

:GETNEXT
shift
if NOT [%1]==[] GOTO DOMOVE

:END
ECHO ARCHIVE finished
Pause
exit
-------------------------------------------------------------------------- files
in
a folder in "My Documents" and move them to an Archive folder while
maintaining their directory structure!



:

Fine, now let's have a look at your batch file!


The Message appears in a window titled with the name of the batch file:
Windows cannot access the specified device, path, or file. You
may
not
have the appropriate permissions to access the item.

Thans again,
Roger

:


What is the maximum number of parameters that can be passed to
a
batch
command? I get a strange error message if I use more than
about
20.
If
that
is the limit, can it be raised.

Thanks
ROGER

It would be helpful if you could quote the "strange error" you
observe so that we don't have to guess what your problem
might be. Regardless of this, I ran the batch file below and
it worked perfectly well with 35 parameters.

@echo off
set count=1
:again
echo Parm%count%=%1
set /a count=%count%+1
shift
pause
if %count% LEQ 35 goto again
 
Thanks, I'll check out xxcopy, but that does not solve my original problem!
Is there a limit on total parameter string length? That would make sence
since all these names are full qualified. Where do I find it's value ...
registry?
Roger

Pegasus said:
xxcopy.exe is a third-party utility that is far more versatile
than xcopy.exe. It has so many switches that you need
to run the command xxcopy /help > xxcopy.txt in order to
work out which one is best for you. In your case the /rc
switch is probably the right one: It deletes the source file(s)
after copy.


Roger said:
Pegasus,
Again thanks for your help! I am not typing in the file names. This is
being executed via a link in the "send to" menu. I can select files from a
list, right click, select "SEND TO" and select this batch file from that drop
down list. It should execute the fatch with all the selected file names as
parameters.

Also I am not familiar with the XXCOPY command. Where can I get Info on
it??? Remember I want to move the files not copy them!

Roger

Pegasus said:
I don't think your problem has anything to do with the
number of parameters. It is probably caused by one of
the following:
- The last parameter is not what you think it is. Add a trap
to your batch file so that every parameter gets echoed to
the screen.
- You may have exceeded the maximum total length of the
parameter string that cmd.exe can process. Maybe you're
running out of environment space. Again you can
verify this by echoing every parameter to the screen.

While your batch file uses a number of advanced features,
I wonder this is the best way to solve your problem. The
following fragment of a batch file would do much the same
as your own batch file but possibly in a more robust and
certainly in a more manageable way:

@echo off
if [%1]==[] goto :eof
:again
xxcopy /s /rc /yy %1 d:\Target\
shift
if not [%1]==[] goto again

I also wonder how you intend to enter 25 or more file names
to be archived. Sounds like a lot of typing! It would be easier
to use some suitable criterion, e.g. file date, archive attribute etc.

OK, Here it is. I works for 25 parameters but fails with 26!
--------------------------------------------------------------------------
---------------------
@echo off
echo Archive Routine vF.0

:DOMOVE
set Source=%1

set Name=%~n1
rem Name is the Folder name or filename w/o extension
set Short=%~sp1
rem Temp will be the path in short form
set TestDir=%Short:~1,7%
rem TestDir is the first 7 digits of the top path
rem It will be "DOCUME~" for "Documents and Settings"

:TESTSOURCE
if "%TestDir%"=="DOCUME~" GOTO CHCKATTR
Echo %Source% must be in "My Documents"
goto GETNEXT

:CHCKATTR
set Attrlist=%~a1
rem Attrlist is the attributes of the directory or file
set AttrFD=%Attrlist:~0,1%
rem AttrFD will be "d" for a directory or "-" for a file
echo %AttrFD%

:SETTARGET
set TarDir=%~dp1
rem TarDir is the full path of the folder containing the
source
set Target=%TarDir:Documents and Settings=Archive%
rem Target is the target directory formed by replacing
rem "Documents and ..." with "ARCHIVE"

:MOVE
if not "%AttrFD%"=="d" goto MOVEIT
echo %source% is a directory
goto getnext
rem It's a File

:MOVEIT
xcopy /T /I %1 "%Target%"
rem This creates the directory structure
move /Y %1 "%Target%"
rem This will move a single file
if %errorlevel% EQU 0 GOTO OK
echo ARCHIVE NOT SUCCESSFUL code%errorlevel%f
GOTO END

:OK
echo . %Name%
echo . Successfully Archived to:
echo . %Target%

:GETNEXT
shift
if NOT [%1]==[] GOTO DOMOVE

:END
ECHO ARCHIVE finished
Pause
exit
--------------------------------------------------------------------------
---------------------
I execute it via a link on the sent to context menu. I can select files
in
a folder in "My Documents" and move them to an Archive folder while
maintaining their directory structure!



:

Fine, now let's have a look at your batch file!


The Message appears in a window titled with the name of the batch
file:
Windows cannot access the specified device, path, or file. You may
not
have the appropriate permissions to access the item.

Thans again,
Roger

:


What is the maximum number of parameters that can be passed to a
batch
command? I get a strange error message if I use more than about
20.
If
that
is the limit, can it be raised.

Thanks
ROGER

It would be helpful if you could quote the "strange error" you
observe so that we don't have to guess what your problem
might be. Regardless of this, I ran the batch file below and
it worked perfectly well with 35 parameters.

@echo off
set count=1
:again
echo Parm%count%=%1
set /a count=%count%+1
shift
pause
if %count% LEQ 35 goto again
 
Your knowledge of batch file techniques is more than
adequate to explore if the total parameter string length
limit is 1000, 2000 or 32,000 characters! If you wish
to obtain a more definite answer then I recommend you
repost your question in a newsgroup that looks at
nothing other than batch files: alt.msdos.batch.nt.


RogerJ said:
Thanks, I'll check out xxcopy, but that does not solve my original problem!
Is there a limit on total parameter string length? That would make sence
since all these names are full qualified. Where do I find it's value ...
registry?
Roger

Pegasus said:
xxcopy.exe is a third-party utility that is far more versatile
than xcopy.exe. It has so many switches that you need
to run the command xxcopy /help > xxcopy.txt in order to
work out which one is best for you. In your case the /rc
switch is probably the right one: It deletes the source file(s)
after copy.


Roger said:
Pegasus,
Again thanks for your help! I am not typing in the file names. This is
being executed via a link in the "send to" menu. I can select files
from
a
list, right click, select "SEND TO" and select this batch file from
that
drop
down list. It should execute the fatch with all the selected file
names
as
parameters.

Also I am not familiar with the XXCOPY command. Where can I get Info on
it??? Remember I want to move the files not copy them!

Roger

:

I don't think your problem has anything to do with the
number of parameters. It is probably caused by one of
the following:
- The last parameter is not what you think it is. Add a trap
to your batch file so that every parameter gets echoed to
the screen.
- You may have exceeded the maximum total length of the
parameter string that cmd.exe can process. Maybe you're
running out of environment space. Again you can
verify this by echoing every parameter to the screen.

While your batch file uses a number of advanced features,
I wonder this is the best way to solve your problem. The
following fragment of a batch file would do much the same
as your own batch file but possibly in a more robust and
certainly in a more manageable way:

@echo off
if [%1]==[] goto :eof
:again
xxcopy /s /rc /yy %1 d:\Target\
shift
if not [%1]==[] goto again

I also wonder how you intend to enter 25 or more file names
to be archived. Sounds like a lot of typing! It would be easier
to use some suitable criterion, e.g. file date, archive attribute etc.

OK, Here it is. I works for 25 parameters but fails with 26!
--------------------------------------------------------------------------
---------------------
@echo off
echo Archive Routine vF.0

:DOMOVE
set Source=%1

set Name=%~n1
rem Name is the Folder name or filename w/o extension
set Short=%~sp1
rem Temp will be the path in short form
set TestDir=%Short:~1,7%
rem TestDir is the first 7 digits of the top path
rem It will be "DOCUME~" for "Documents and Settings"

:TESTSOURCE
if "%TestDir%"=="DOCUME~" GOTO CHCKATTR
Echo %Source% must be in "My Documents"
goto GETNEXT

:CHCKATTR
set Attrlist=%~a1
rem Attrlist is the attributes of the directory or file
set AttrFD=%Attrlist:~0,1%
rem AttrFD will be "d" for a directory or "-" for a file
echo %AttrFD%

:SETTARGET
set TarDir=%~dp1
rem TarDir is the full path of the folder containing the
source
set Target=%TarDir:Documents and Settings=Archive%
rem Target is the target directory formed by replacing
rem "Documents and ..." with "ARCHIVE"

:MOVE
if not "%AttrFD%"=="d" goto MOVEIT
echo %source% is a directory
goto getnext
rem It's a File

:MOVEIT
xcopy /T /I %1 "%Target%"
rem This creates the directory structure
move /Y %1 "%Target%"
rem This will move a single file
if %errorlevel% EQU 0 GOTO OK
echo ARCHIVE NOT SUCCESSFUL code%errorlevel%f
GOTO END

:OK
echo . %Name%
echo . Successfully Archived to:
echo . %Target%

:GETNEXT
shift
if NOT [%1]==[] GOTO DOMOVE

:END
ECHO ARCHIVE finished
Pause
exit
--------------------------------------------------------------------------
---------------------
I execute it via a link on the sent to context menu. I can select files
in
a folder in "My Documents" and move them to an Archive folder while
maintaining their directory structure!



:

Fine, now let's have a look at your batch file!


The Message appears in a window titled with the name of the batch
file:
Windows cannot access the specified device, path, or file.
You
may
not
have the appropriate permissions to access the item.

Thans again,
Roger

:


What is the maximum number of parameters that can be
passed to
a
batch
command? I get a strange error message if I use more than about
20.
If
that
is the limit, can it be raised.

Thanks
ROGER

It would be helpful if you could quote the "strange error" you
observe so that we don't have to guess what your problem
might be. Regardless of this, I ran the batch file below and
it worked perfectly well with 35 parameters.

@echo off
set count=1
:again
echo Parm%count%=%1
set /a count=%count%+1
shift
pause
if %count% LEQ 35 goto again
 
On Sat, 21 Jan 2006 08:38:02 -0800, "Roger"
OK, Here it is. I works for 25 parameters but fails with 26!

"26" as in "letters of the alphabet"? I can't see a mechanism...
....or is it a limit on environment space for the arguments?


---------- ----- ---- --- -- - - - -
Don't pay malware vendors - boycott Sony
 
cquirke (MVP Windows shell/user) said:
On Sat, 21 Jan 2006 08:38:02 -0800, "Roger"


"26" as in "letters of the alphabet"? I can't see a mechanism...
...or is it a limit on environment space for the arguments?



Don't pay malware vendors - boycott Sony

Since the parameters are numbered 1..x, they have nothing
to do with the letters of the alphabet. Try it for yourself!
 
"cquirke (MVP Windows shell/user)"
Since the parameters are numbered 1..x, they have nothing
to do with the letters of the alphabet. Try it for yourself!

Swotteye thort.

As someone's suggested, insert something like this...

Echo Current "%%1" =
Echo.
Echo "%1"
Echo.
Pause

....to see what's going on. If the last parameter is trunc


---------- ----- ---- --- -- - - - -
Don't pay malware vendors - boycott Sony
 
Back
Top