China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-17 21:23
中国DOS联盟论坛 » DOS疑难解答 & 问题讨论 (解答室) » Please help me take a look at this batch file View 707 Replies 4
Original Poster Posted 2006-01-31 12:56 ·  中国 福建 福州 电信
初级用户
Credits 136
Posts 12
Joined 2004-01-25 00:00
22-year member
UID 16055
Gender Male
Status Offline
Here is a batch file. I don't understand it. I don't understand SHIFT or the parameters.
REM MYCOPY.BAT copies any number of
REM files to a directory. The command
REM is MYCOPY DIR FILES

SET TODIR=%1
:ONE
SHIFT
IF"%1"=" "GOTO TWO
COPY %1 %TODIR%
GOTO ONE
:TWO
SET TODIR=
ECHO ALL DONE

Thanks in advance
Floor 2 Posted 2006-01-31 14:30 ·  中国 福建 泉州 电信
初级用户
Credits 86
Posts 32
Joined 2006-01-27 15:56
20-year member
UID 49579
Status Offline
I'm just thinking of learning this. Friend in the post above, could you send me a SHIFT program? I'm trying to study it, thanks.
lks205#163.com (please change # to @)
Floor 3 Posted 2006-01-31 16:29 ·  中国 福建 福州 电信
初级用户
Credits 136
Posts 12
Joined 2004-01-25 00:00
22-year member
UID 16055
Gender Male
Status Offline
Replied already, thanks
Floor 4 Posted 2006-01-31 18:19 ·  中国 广东 广州 白云区 电信
金牌会员
★★★★
D◎$ Fαп
Credits 4,562
Posts 1,883
Joined 2004-01-19 00:00
22-year member
UID 15812
Gender Male
From 广东广州
Status Offline
The function of Shift is to move the command-line parameters forward, that is, %2 becomes %3, %2 becomes %1, and so on.
----====≡≡≡≡ 我的至爱,永远是MSDOS!≡≡≡≡====----
Floor 5 Posted 2006-01-31 20:24 ·  中国 福建 泉州 电信
初级用户
Credits 86
Posts 32
Joined 2006-01-27 15:56
20-year member
UID 49579
Status Offline
SHIFT


  Changes the position of replaceable parameters in a batch program.

  

  Syntax

  
  SHIFT

  SHIFT─Notes

  How the SHIFT command works

  The SHIFT command changes the values of replaceable parameters %0 to %9 by copying each parameter to the previous parameter. That is, the value of %1 is copied to %0, the value of %2 is copied to %1, and so on. This command is useful for batch files that perform the same operation on a series of parameters.

  

  :m567

  Using more than 10 command-line parameters

  

  Using the SHIFT command, a batch file can also receive more than 10 command-line parameters. If the specified command-line parameters exceed 10, then the parameters appearing after the 10th parameter (%9) will in turn be shifted into (%9).

  

  Restoring replaceable parameters

  The SHIFT command is irreversible. Once the SHIFT command has been executed, the first parameter before the SHIFT command (%0) cannot be restored.

  

  

  SHIFT─Example

  The following batch file MYCOPY.BAT shows how to use the SHIFT command to process any number of command-line parameters and copy a series of files to a specified directory. The parameters used are the directory name followed by a series of file names.

  

  @echo off

  rem MYCOPY.BAT copies any number of files

  rem to a directory。

  rem The command uses the following syntax:

  rem mycopy dir file1 file2 ...

  set todir=%1

  :getfile

  shift

  if "%1"=="" goto end

  copy %1 %todir%

  goto getfile

  :end

  set todir=

  echo All done

  
Forum Jump: