Put command output into a variable

前端 未结 4 1592
耶瑟儿~
耶瑟儿~ 2021-01-24 03:27

Given a directory with the following files

image1.txt
image2.txt
image3.txt

I want to get the oldest file (let the files be sorted by data, old

4条回答
  •  失恋的感觉
    2021-01-24 04:00

    For /F %%A in ('"dir /b /od C:\test\image*.txt|findstr ^1"') do set myVar=%%A
    

    You could do it through For loop, try that in command line, I just tested it and it works fine

    Output:

    set myVar=image1.txt
    

    On executing Set on command line you can see:

    myVar=image1.txt
    NUMBER_OF_PROCESSORS=2
    

提交回复
热议问题