我想知道如何在批處理檔案中排除檔案。目前,批處理檔案中的 cl.exe 編譯行如下所示:
cl /c ..\source\*.c
那么我怎么說我想從構建中構建除“file_not_needed.c”之外的所有檔案?
uj5u.com熱心網友回復:
具有要排除的檔案擴展名的檔案c可以通過更改檔案擴展名來臨時重命名以排除它們。
用于在命令提示符視窗或批處理檔案中使用的單個C源代碼檔案的單個命令列:
ren ..\source\file_not_needed.c file_not_needed.c.tmp & cl.exe /c ..\source\*.c & ren ..\source\file_not_needed.c.tmp file_not_needed.c
在批處理檔案中使用多個C源代碼檔案的多行解決方案:
for %%I in (file_not_needed "one more file not needed") do ren "..\source\%%~I.c" "%%~I.c.tmp"
cl.exe /c ..\source\*.c
for %%I in ("..\source\*.c.tmp") do ren "%%I" "%%~nI"
所有要排除的檔案必須在第一個FOR回圈的圓括號內指定,使用空格、逗號或分號作為不帶檔案擴展名的檔案名之間的分隔符。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/507906.html
