Reputation: 179
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
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
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:
Create and assign an instance of FileSystemObject
using something like Set fso = CreateObject("Scripting.FileSystemObject")
.
For Each Folder In fso.GetFolder(...).SubFolders
iterates through all subfolders. For deep iteration, use recursion.
There is also Files
which lists all files of a Folder
.
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