简体   繁体   中英

List directories in Batch

I have multiple folders with a structure like this inside:

aaa
    000
        important
            v001
            v002
            v003
        not_important
            something_else
    001
        important
            v001
            v002
            v003
        not_important
            something_else
    002
        important
            v001
            v002
            v003
        not_important
            something_else
bbb
    000
        important
            v001
            v002
            v003
        not_important
            something_else
    001
        important
            v003
        not_important
            something_else
    002
        important
            v001
            v002
            v003
        not_important
            something_else
ccc
    000
        important
            v001
            v002
            v003
        not_important
            something_else
    001
        important
            v001
            v002
            v003
            v004
            v005
        not_important
            something_else
    002
        important
            v001
            v002
            v003
        not_important
            something_else

One of the folders is called v00? , which contains a specific version of a file. Now I want to list all the dates of the latest files.

However here are my problems:

  • I assume I cant use a recursive function, because I have some folders that I don't care about (not_important in my example above)
  • I only want the lastest Version
  • The versions don't always start at one and are not limited by number
  • The Folder names are not an easy aaa, bbb, 000, structure and cannot be looped by name, the also not nessecarily repeat (Folder1 and Folder2 are not the same, just the amount of folders/layers that they go in) -I need to iterate through the outer folders as well.

How can I only filter out the latest Version of these folders?

I tried this, however I can't get multiple layers in with that function and the "dir" command gives me everything

"FOR /D %%d IN (*.*) DO ("

How can I solve this?

My current code looks like this>

@echo off

setlocal 

for /D %%d in (*.*) do (
    echo %%d
    cd %%d

        for /D %%e in (*.*) do (
        echo %%e
        cd %%e
                for /D %%f in (*.*) do (
                    cd %%f
                    echo %%f



                    Insert Here CD ??



                    for /f "tokens=*" %%1 in ('dir /b /ad /on v*') do (
                        set latestdir=%%1
                    )

                    echo Latest directory name=%latestdir%

                        cd %latestdir%\fullres
                            pause
                        cd..


                )
        cd..
        )
    cd ..

)
pause
@echo off
setlocal enabledelayedexpansion

for /r /d %%A in (\v00*) do (
    pushd "%%~A\.."
    for /d %%B in (v00*) do set "subfolder=%%~B"
    if not "!save!" == "!cd!" echo !cd!\!subfolder!
    set "save=!cd!"
    popd
)

This recurses through all the directories in the current directory and searches for a match of \\v00* . It will pushd into each matched directory parent dir found and then the nested for loop searches for the last matching subfolder of v00* . If the saved current directory does not match the current directory then the matched directory path will be echoed. The current directory will be saved for the next loop and popd will return to the initial directory.

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