![](/img/trans.png)
[英]Add error handling to existing Windows batch script-> to copy the newest file from a directory
[英]Existing Directory Not Found by Batch Script
在向用戶發出一系列提示之后,我的批處理腳本將匯編一個目錄路徑:
set RELEASE_PATH=!RELEASE_DRIVE!:\!CUSTOMER!\files\!RELEASE_LABEL!
我面臨的問題是嘗試檢測此路徑末尾的文件夾是否已經存在時。 您可能認為這很簡單,但是即使路徑存在,路徑評估也總是失敗。 但是,當我從命令行運行相同的if
語句時,它可以工作。 -_-
if not exist !RELEASE_PATH! (
echo DEBUG: Path %CD%\%RELEASE_LABEL% exists
mkdir %RELEASE_LABEL%
) else (
echo DEBUG: Path %CD%\%RELEASE_LABEL% does not exist
)
運行批處理文件總是會回顯DEBUG: Path %CD%\\%RELEASE_LABEL% does not exist
的行DEBUG: Path %CD%\\%RELEASE_LABEL% does not exist
即使它確實存在。 僅供參考,我同時設置了EnableExtentions
和EnableDelayedExpansion
。
典型的發布路徑可能是R:\\Widget_Co\\files\\Release_12.1
。 任何想法或想法將不勝感激。
我認為問題與設置EnableDelayedExpansion
。 我能夠使用for循環將這種解決方法放在一起:
rem ## This clunky workaround with the for loop is required because a simple
rem ## `if not exist` command isn't working. It is believed that this has
rem ## something to do with EnableDelayedExpansion being set. There is only one
rem ## element in the RELEASE_PATH variable being evaluated in this loop.
for /F %%i in ("!RELEASE_PATH!") do (
if not exist %%i (
mkdir %%i
)
)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.