batch file to list folders within a folder to one level

后端 未结 3 927
轮回少年
轮回少年 2021-02-04 01:57

I have searched and searched to no avail so apologies if the answer does exist.

I am not very good with batch files so please keep this in mind.

All I am after i

3条回答
  •  逝去的感伤
    2021-02-04 02:47

    Dir

    Use the dir command. Type in dir /? for help and options.

    dir /a:d /b
    

    Redirect

    Then use a redirect to save the list to a file.

    > list.txt
    

    Together

    dir /a:d /b > list.txt
    

    This will output just the names of the directories. if you want the full path of the directories use this below.


    Full Path

    for /f "delims=" %%D in ('dir /a:d /b') do echo %%~fD
    

    Alternative

    other method just using the for command. See for /? for help and options. This can output just the name %%~nxD or the full path %%~fD

    for /d %%D in (*) do echo %%~fD
    

    Notes

    To use these commands directly on the command line, change the double percent signs to single percent signs. %% to %

    To redirect the for methods, just add the redirect after the echo statements. Use the double arrow >> redirect here to append to the file, else only the last statement will be written to the file due to overwriting all the others.

    ... echo %%~fD>> list.txt
    

提交回复
热议问题