windows batch dir command get last modified directory starting with string

跟風遠走 提交于 2019-12-24 14:18:57

问题


I want to get the last modified directory starting with a string stringEx... in a windows batch file.

For example: I have a folder containing sub-directories like this :

- Directory
  -Subdirectory1
  -Subdirectory2
  -Anothersubdirectory
....

I tried with this but it doesn't work:

@echo off
Setlocal EnableDelayedExpansion
Set foundedFolder

FOR /F %%i IN ('dir C:\Directory | subtsr "Anoth*" /b /ad-h /od') DO (SET a=%%i)

%foundedFolder%=%a%

Any ideas?


回答1:


for /f "delims=" %%a in ('dir /b /ad-h /od "Anoth*"') do set "latestDir=%%~a"
echo(%latestDir%


来源:https://stackoverflow.com/questions/20132814/windows-batch-dir-command-get-last-modified-directory-starting-with-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!