我想列出最新的目錄文件夾不使用單詞「補丁」如何處理目錄的文件名中的一個批處理文件
for /f "tokens=*" %%a in ('dir /b /od') do (
// some if loop to ensure that newest is not set to something that ends with "-patch".
set newest=%%a
)
我想列出最新的目錄文件夾不使用單詞「補丁」如何處理目錄的文件名中的一個批處理文件
for /f "tokens=*" %%a in ('dir /b /od') do (
// some if loop to ensure that newest is not set to something that ends with "-patch".
set newest=%%a
)
for /f "delims=" %%a in ('dir /b /s /o-d /ad ^|findstr /v /e /c:"-patch" 2^>nul') do (
set "newest=%%~fa"
goto :break
)
:break
echo newest : %newest%
setlocal enableextensions
for /f "tokens=*" %%a in ('dir /b /od') do (
set "a=%%a"
if /i not "!a:~-5!"=="patch" set "file=%%a"
)
結束file
將包含所需的文件夾名稱。
使用'/ od'命令可能會失敗。如果名稱合適,請使用'/ on'。 –
不起作用。仍然帶有'-patch'的目錄被列爲最近的目錄。 –
試試這個:
for /f "delims=" %%a in ('dir /b /od /ad ^|findstr /evi "patch" 2^>nul') do set "RecentFolder=%%~a"
echo %RecentFolder%
我不能在使用管道爲()。你可以嗎? –
你可以如果他們用'^' – npocmaka
轉義不起作用,結果是空字符串。但是該文件夾確實包含不以'-patch'結尾的其他目錄。 –