Helge said:
Hallo NG!
W7/64 Home Premium.
I have a folder-tree that ends in many empty folders.
Does someone now a tool that counts (and can delete)
the empty ones, a batch eventually?
Thanks.
Vy 73! Helge
http://www.winfrastructure.net/article.aspx?BlogEntry=VBScript-to-check-if-folder-is-empty
If objFolder.Files.Count = 0 And objFolder.SubFolders.Count = 0 Then
MsgBox "The folder is empty"
Then all you need, is some recursive code to walk
the file tree. I got a chunk of that around here
somewhere... Got it off the web. Store in file
"listdir5.vbs". You'll need to combine the contents from
the above link, into some directory traversing code
like this example. Google on scanSubFolders(objFolder)
for more examples.
' // **************************************
' // Script to list files.
' // List is tab separated.
' // Based on someone elses script, with slight changes.
' // Output looks like this. (Size <tab> Date <tab> Path)
' //
' // 32964 1/19/2012 1:06:32 AM C:\test.txt
' //
' // This program has no command line arguments. You enter the
' // topDir as a string in the line below. That's where it'll start
' // scanning. The output always goes to ScriptOutput1.txt . Change
' // the name to something you like.
' //
' // Program has no error handling. I just changed another script, to make this one.
Dim objFSO
Dim tab
tab=chr(9)
topDir = "C:\Downloads\contig_test\hello\"
set objFSO = CreateObject("Scripting.FileSystemObject")
' Create text file to store output data
' When you launch this in MSDOS window, file will be created in current working directory.
Set OutputFile = objFSO.CreateTextFile("ScriptOutput1.txt", True)
Set objFolder = objFSO.GetFolder(topDir)
Set colFiles = objFolder.Files
Set colFolders = objFolder.SubFolders
For Each objFile in colFiles
Outputfile.write(objFile.size)
Outputfile.write(tab)
Outputfile.write(objFile.DateLastModified)
Outputfile.write(tab)
Outputfile.writeLine(objFile.Path)
Next
' Call a separate subroutine, to output file contents of subfolders
For Each objSubFolder In colFolders
ScanSubFolders(objSubFolder)
Next
' Close text file
OutputFile.Close
' Program ends here...
' // **************************************
Sub scanSubFolders(objFolder)
Set colFiles = objFolder.Files
Set colFolders = objFolder.SubFolders
For Each objFile in colFiles
Outputfile.write(objFile.size)
Outputfile.write(tab)
Outputfile.write(objFile.DateLastModified)
Outputfile.write(tab)
Outputfile.writeLine(objFile.Path)
Next
For Each objSubFolder In colFolders
ScanSubFolders(objSubFolder)
Next
End Sub
*******
HTH,
Paul