×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

VBS to spreadsheet of folders subfolders subsubfolders (and so on......) and the files listed inside

VBS to spreadsheet of folders subfolders subsubfolders (and so on......) and the files listed inside

VBS to spreadsheet of folders subfolders subsubfolders (and so on......) and the files listed inside

(OP)
this is what i have can someone modify it ? or guide me i am a real noob didnt do anything with vbs for a long time

objStartFolder = "C:\Folder\"



Set objExcel = CreateObject("Excel.Application")

objExcel.Visible = True

objExcel.Workbooks.Add

intRow = 2



objExcel.Cells(1, 1).Value = "Folder"

objExcel.Cells(1, 2).Value = "File Name"



Set objFSO = CreateObject

("Scripting.FileSystemObject")

Set objFolder = objFSO.GetFolder(objStartFolder)



Set colFiles = objFolder.Files

For Each objFile in colFiles

objExcel.Cells(intRow, 1).Value = objfolder.Name

objExcel.Cells(intRow, 2).Value = objFile.Name

intRow = intRow + 1

Next



ShowSubfolders objFSO.GetFolder(objStartFolder)



Sub ShowSubFolders(Folder)

For Each Subfolder in Folder.SubFolders

objExcel.Cells(intRow, 1).Value = Subfolder.Path



Set objFolder = objFSO.GetFolder(Subfolder.Path)

Set colFiles = objFolder.Files

For Each objFile in colFiles

objExcel.Cells(intRow, 2).Value = objFile.Name

intRow = intRow + 1

Next



ShowSubFolders Subfolder

Next

End Sub



objExcel.Range("A1:B1").Select

objExcel.Selection.Interior.ColorIndex = 19

objExcel.Selection.Font.ColorIndex = 11

objExcel.Selection.Font.Bold = True

objExcel.Cells.EntireColumn.AutoFit



MsgBox "Done"

RE: VBS to spreadsheet of folders subfolders subsubfolders (and so on......) and the files listed inside

What's not working in your code?

RE: VBS to spreadsheet of folders subfolders subsubfolders (and so on......) and the files listed inside

So it looks like you are trying to create a spreadsheet of every subfolder and every file under a specific path. The logic of the code looks OK, what isn't happening that you want to? I ran this script against my temp folder and it worked fine.

I hope that helps.

Regards,

Mark

No trees were harmed in posting this message, however a significant number of electrons were terribly inconvenienced.

Check out my scripting solutions at http://www.thespidersparlor.com/vbscript

Work SMARTER not HARDER.

RE: VBS to spreadsheet of folders subfolders subsubfolders (and so on......) and the files listed inside

(OP)
wekk yes that is what i tryed but the problem is that the rootfolsder used (called folder) is added and the first layer of folders in there but not the folders in the second layer (sorry for my english is not that good)

RE: VBS to spreadsheet of folders subfolders subsubfolders (and so on......) and the files listed inside

OK, so what you are trying to do is called a recursive listing. Here is an example:

CODE --> VBScript

Set objFSO = CreateObject("Scripting.Filesystemobject")
StartFolder = "C:\Windows"

Set oRoot = objFSO.GetFolder(StartFolder)
WScript.Echo oRoot.Name

For Each oFile In oRoot.Files
	WScript.Echo vbTab & vbTab & oFile.Name
Next

For Each oSubFolder In oRoot.SubFolders
	WScript.Echo oSubFolder.Name
	GetSubInfo oSubFolder.Path
Next



Function GetSubInfo(oSubFolder)
	Set oFolder = objFSO.GetFolder(oSubFolder)
	For Each oFile In oFolder.Files
		WScript.Echo vbTab & vbTab & oFile.Name
	Next
	For Each oSub In oFolder.SubFolders
		WScript.Echo oSub.Name
		GetSubInfo oSub.Path
	Next
End Function 

I hope that helps.

Regards,

Mark

No trees were harmed in posting this message, however a significant number of electrons were terribly inconvenienced.

Check out my scripting solutions at http://www.thespidersparlor.com/vbscript

Work SMARTER not HARDER.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close