• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

The SHIFT Command Redux

The SHIFT Command Redux

Now that you know a little about how IF works, I can show you how to use the SHIFT command introduced earlier. Recall that SHIFT operates by shuffling the batch file parameters down one position, so that %1 becomes %0, %2 becomes %1, and so on. The most common use of this apparently strange behavior is to process batch files with an unknown number of parameters. As an example, let’s redo the SUPERDELETE.BAT batch file so that it can delete any number of file specifications:

@ECHO OFF
IF "%1"=="" GOTO NO_FILES
:START
ECHO Now deleting %1 . . .
DEL %1
SHIFT
IF "%1"=="" GOTO DONE
GOTO START
:NO_FILES
ECHO You didn't enter a file spec!
:DONE


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint