Ruriko
Ruriko

Reputation: 179

Create txt file in every subfolder

I am running windows server 2003. I have a directory that contains hundreds of sub-folders. I want to auto create txt file in each subfolder that will list all the files in that subfolder. Some folders uses special/Chinese characters. How can I do this with CMD? or any other language or tool

Upvotes: 1

Views: 1745

Answers (2)

Ansgar Wiechers
Ansgar Wiechers

Reputation: 200563

Using batch:

@echo off
chcp 65001 >nul
for /r "C:\your\dir" %%d in (.) do dir /a:-d "%%~fd" > "%%~dpnd\dirlist.txt"

Upvotes: 2

krlmlr
krlmlr

Reputation: 25484

The FileSystemObject of Windows Scripting contains everything you need, but you'll need to write a bit of VBScript code to plug it together:

  1. Create and assign an instance of FileSystemObject using something like Set fso = CreateObject("Scripting.FileSystemObject").

  2. For Each Folder In fso.GetFolder(...).SubFolders iterates through all subfolders. For deep iteration, use recursion.

  3. There is also Files which lists all files of a Folder.

  4. CreateTextFile does what it promises, and also has a unicode option.

If you do not need deep iteration, a CMD solution would be probably shorter, though I suspect you will run into Unicode problems.

Upvotes: 0

Related Questions