Windows / Tạo tập tin txt của các thư mục con có tên tệp trong đó


1

Tôi có một thư mục trên ổ cứng chứa 1000 thư mục con. Những thư mục con này chứa các tệp và đôi khi nhiều thư mục con hơn. Bây giờ những gì tôi muốn có là một tập lệnh tạo tệp .txt cho mỗi thư mục ở cấp độ đầu tiên. Chúng sau đó chứa một danh sách các tên tệp và cuối cùng là tên của các thư mục con và thư mục con. Điều quan trọng là không nhồi nhét tất cả vào một tệp mà thành các tệp riêng biệt.

Nó sẽ giống như thế này

Name of the first folder.txt
Name of the second folder.txt
Name of the third folder.txt
Name of the fourth folder.txt
Name of the fifth folder.txt
Name of the sixth folder.txt

Tên của thư mục đầu tiên nên chứa một danh sách như thế này

Name of the first file.xyz
Name of the second file.zzz
Name of the third file.xyz
Name of the fourth file.zzz
Name of the fifth file.xyz

Name of Subfolder 1
  Name of file.zzz
  Name of another file.zzz

Name of Subfolder 2
  Name of file.xyz

  Name of Subsubfolder 1
    Name of file.xyz
    Name of file2.zzz

Bất cứ ai có thể giúp tôi?
user828591

Câu trả lời:


0

Giải pháp nhanh chóng bằng cách sử dụng tree lệnh in cấu trúc thư mục.

@echo off

:: for each directory...
for /d %%D in (*) do (
  :: we'll go into it...
  cd %%~nxD
  :: use the 'tree' command to output its 
  :: structure in a nice way...
  tree /a /f > ..\%%~nxD.txt
  :: go back...
  cd ..

  :: remove the first 3 (useless) lines from the 'tree' output
  echo %%~nxD > stackoverflowrules.tmp
  for /f "skip=3 delims=*" %%a in (%%~nxD.txt) do (
    echo.%%a >> stackoverflowrules.tmp
  )
  copy /y stackoverflowrules.tmp %%~nxD.txt
  del /f /q stackoverflowrules.tmp  
)
Khi sử dụng trang web của chúng tôi, bạn xác nhận rằng bạn đã đọc và hiểu Chính sách cookieChính sách bảo mật của chúng tôi.
Licensed under cc by-sa 3.0 with attribution required.