2017-02-22 47 views
2

我是批量编程的新手。我在“Makecab”接受的答案部分找到了这里提到的程序here。我在这里插入:行中的分号 - 批号

;@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 ;;;;; 

它在每行的开始处使用分号有什么区别?还有一些行有多个分号,为什么?

回答

3

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

但是这是一种polyglot脚本 - 它也是一个有效的makecab directive其中;意味着评论。这就是为了减少IO操作并使脚本更快一点,并尽可能避免不那么容易读取线路。有些行用更多分号来强调真实的评论行。

同样的伎俩,也可以用reg files

+0

使用该方法的批号变成为了使MakeCab指令的创建文件简单复杂化;然而,有很多批次的人会被这个技巧弄糊涂,很少有MakeCab用户可以欣赏它。恕我直言,通过标准批处理代码创建指令文件将是正确的选择... – Aacini

0

我只涉及批处理编程来执行简单的函数,所以我可能是错的,但我从来没有遇到过在行的开头使用分号。我认为这样做是为了基本评价线条。如果我是你,当你继续使用批处理文件进行编程时,我不会关注这一点。