Recursively List all directories and files

后端 未结 7 1783
萌比男神i
萌比男神i 2021-01-30 20:19

I would like to receive the following output.

Suppose the directory structure on the file system is like this:

  -dir1
      -dir2
        -file1
        -fi         


        
7条回答
  •  野的像风
    2021-01-30 20:59

    On Windows, you can do it like this as most flexibile solution that allows you to additionally process dir names.

    You use FOR /R to recursively execute batch commands.

    Check out this batch file.

    @echo off
    SETLOCAL EnableDelayedExpansion
    
    SET N=0
    for /R %%i in (.) do (
         SET DIR=%%i
    
         ::put anything here, for instance the following code add dir numbers.
         SET /A N=!N!+1
         echo !N! !DIR!
    )
    

    Similary for files you can add pattern as a set instead of dot, in your case

     (*.*)
    

提交回复
热议问题