- Batch File Parameters
- Posted by Roger on January 20th, 2006
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
- Posted by Pegasus \(MVP\) on January 20th, 2006
"Roger" <Roger@discussions.microsoft.com> wrote in message
news:234748FF-173C-4C53-872A-05AAF5C54B64@microsoft.com...
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
- Posted by Roger on January 21st, 2006
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
"Pegasus (MVP)" wrote:
- Posted by Pegasus \(MVP\) on January 21st, 2006
Fine, now let's have a look at your batch file!
"Roger" <Roger@discussions.microsoft.com> wrote in message
news:FDCB0495-1DF6-4199-918C-E7AF3500E27D@microsoft.com...
- Posted by Roger on January 21st, 2006
OK, Here it is. I works for 25 parameters but fails with 26!
-----------------------------------------------------------------------------------------------
@echo off
echo Archive Routine vF.0
OMOVE
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
ocuments 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)" wrote:
- Posted by Pegasus on January 22nd, 2006
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" <Roger@discussions.microsoft.com> wrote in message
news:451A4DBE-9D40-4C41-9233-782146D400AE@microsoft.com...
- Posted by Roger on January 22nd, 2006
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" wrote:
- Posted by Pegasus on January 22nd, 2006
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" <Roger@discussions.microsoft.com> wrote in message
news:8243D790-1086-4FA2-818F-0F183334B6C5@microsoft.com...
- Posted by RogerJ on January 22nd, 2006
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" wrote:
- Posted by Pegasus \(MVP\) on January 22nd, 2006
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" <RogerJ@discussions.microsoft.com> wrote in message
news:AA4A1C6F-DC9F-41A2-A13E-E413CEC5DB77@microsoft.com...
- Posted by cquirke (MVP Windows shell/user) on January 22nd, 2006
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?
- Posted by Pegasus \(MVP\) on January 22nd, 2006
"cquirke (MVP Windows shell/user)" <cquirkenews@nospam.mvps.org> wrote in
message news:0138t1dfruohq1gv816rejm7us5jl4akj1@4ax.com...
Since the parameters are numbered 1..x, they have nothing
to do with the letters of the alphabet. Try it for yourself!
- Posted by cquirke (MVP Windows shell/user) on January 27th, 2006
On Mon, 23 Jan 2006 10:37:30 +1100, "Pegasus \(MVP\)"
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