简体   繁体   中英

Windows batch file: choosing a file from a directory based on directory name

I don't do windows batch programming, nor do I need to go that far down the rabbit hole.

I have directory structures as such:

dir1000000/file.txt
dir2000000_1/file.txt
dir2000000_2/file.txt

I need to select the file.txt from the path with the lexicographically greatest value, ie dir2000000_2/file.txt . How do I go about doing this?

Assuming the file is always file.txt and only the directory is variable...

FOR /F "delims=" %%a IN ('DIR /ad/b/on') DO SET mydir=%%a
SET myfile=%mydir%\file.txt

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM