行首的分号 - 批处理

J.D*_*Doo 5 batch-file

我对批处理编程很陌生。我发现这里提到的节目在这里的“Makecab”的接受的答案的一部分。我在这里插入它:

;@echo off

;;;;; rem start of the batch part  ;;;;;
; if "%~2" EQU "" (
;   echo invalid arguments.For help use:
;   echo %~nx0 /h
;)
;for %%a in (/h /help -h -help) do ( 
;   if "%~1" equ "%%~a" (
;       echo compressing directory to cab file  
;       echo %~nx0 directory cabfile
;       echo to uncompress use:
;       echo EXPAND cabfile -F:* .
;   )
; )
;
; set "dir_to_cab=%~f1"
;
; set "path_to_dir=%~pn1"
; set "dir_name=%~n1" 
; set "drive_of_dir=%~d1"
; set "cab_file=%~2"
;
; if not exist %dir_to_cab%\ (
;   echo no valid directory passed
;   exit /b 1
;)

;
;break>"%tmp%\makecab.dir.ddf"
;
;setlocal enableDelayedExpansion
;for /d /r "%dir_to_cab%" %%a in (*) do (
;   
;   set "_dir=%%~pna"
;   set "destdir=%dir_name%!_dir:%path_to_dir%=!"
;   (echo(.Set DestinationDir=!destdir!>>"%tmp%\makecab.dir.ddf")
;   for %%# in ("%%a\*") do (
;       (echo("%%~s#"  /inf=no>>"%tmp%\makecab.dir.ddf")
;   )
;)
;(echo(.Set DestinationDir=!dir_name!>>"%tmp%\makecab.dir.ddf")
;   for %%# in ("%~f1\*") do (
;       
;       (echo("%%~s#"  /inf=no>>"%tmp%\makecab.dir.ddf")
;   )

;makecab /F "%~f0" /f "%tmp%\makecab.dir.ddf" /d DiskDirectory1=%cd% /d CabinetNameTemplate=%cab_file%.cab
;del /q /f "%tmp%\makecab.dir.ddf"
;exit /b %errorlevel%

;;
;;;; rem end of the batch part ;;;;;

;;;; directives part ;;;;;
;;
.New Cabinet
.set GenerateInf=OFF
.Set Cabinet=ON
.Set Compress=ON
.Set UniqueFiles=ON
.Set MaxDiskSize=1215751680;

.set RptFileName=nul
.set InfFileName=nul

.set MaxErrors=1
;;
;;;; end of directives part ;;;;;
Run Code Online (Sandbox Code Playgroud)

在每一行的开头使用分号有什么区别?还有一些行有多个分号,这是为什么?

npo*_*aka 6

分号是批处理文件中的标准分隔符 - 与<space>, <tab>, =, 一起,。所以对于批处理文件,它意味着空白。

但这是一种多语言脚本 - 它也是一个有效的makecab 指令,其中;表示注释。这样做是为了减少IO操作,让脚本更快一点,尽可能避免不那么容易读到的echo something>temp.file行。有些行带有更多的分号,以强调真正的注释行。

同样的技巧也可以用于reg 文件