
Originally Posted by
snb
I'd prefer....
Ha, that was an interesting bit of fun..
I ran this version
Code:
Debug.Print CreateObject("wscript.shell").exec("cmd /c Dir ""H:\Excel0202015Jan2016\ExcelForum\wbSheetMaker\EFldr1_1\EFldr1_1_1\*.xlsx"" /b").StdOut.ReadAll
....................
It gave me the result I expected in the Ctrl G Immediate Window
File1_1_1a.xlsx
File1_1_2b.xlsx
But before it blinks at me something that looks like a Blank Black screen. I blinked happily back, as That and the code line looked something like I have a vague memory from about 30 years ago.
: But that is just a fun code. A nice “one liner.” The simple File listing is nice. But too restrictive to be of much use. It can only do limited stuff – here a list of the Files in the Immediate Window. But it did catch my eye as a neater, al be it restricted version, of something i did recently...
_.... So
_...........
Just to add something here: A simplified code version of some i did here:
Get Value Function Loop through all files in folder and its subfolders
Eileen's Lounge • View topic - Find and Replace Values in all excel files of Directory
It is along the lines of that from Excel Fox. It has a bit where you would ....“you need to write what you need..”.. to do stuff for each File. But it is extended to allow to do stuff for all Folders, Sub Folders, and all Files therein.
And i initially Wrote the codes to give out an explorer type output to a sheet. This shows then the Root type plan of all Files, and Folders ,within a main Folder. ( In this simplified version it gives the Output to the current ActiveSheet)
So it is an extended version of what the snb code gives in the immediate Window. But here it is printing to the Active Sheet rather than the Immediate Window ( I wish i knew how to do a snb version, but I expect it is beyond the limit of a “one liner” anyway... )
When you run the code it asks you for the Folder you want to look at.
Code: ( _ .. in more detail here:
Get Value Function Loop through all files in folder and its subfolders
_....... )
(-.. and the typical output it gives here
Excel Help Forum
_......)
Code:
'
Sub EFDoStuffInFoldersInFolderRecursion()
Dim myFolder, strWB As String
With Application.FileDialog(msoFileDialogFolderPicker)
.Title = "Folder Select ": .AllowMultiSelect = False
If .Show <> -1 Then
Exit Sub
End If
strWB = .SelectedItems(1) & "\"
End With
With CreateObject("Scripting.FileSystemObject")
Set myFolder = .GetFolder(strWB)
End With
Dim CopyNumber As Long: CopyNumber = 1
Range("A1").Value = myFolder.Name: Columns("A:C").AutoFit
Call EFLoopThroughEachFolderAndItsFile(myFolder, 1, CopyNumber)
Columns("A:H").AutoFit
End Sub
Sub EFLoopThroughEachFolderAndItsFile(ByVal fldFldr As Object, ByRef rCnt As Long, ByVal CopyNumberFroNxtLvl As Long)
Dim myFldrs As Object
Dim CopyNumber As Long
If CopyNumber = 0 Then CopyNumber = CopyNumberFroNxtLvl
For Each myFldrs In fldFldr.SubFolders
''''''''Doing stuff for each Folder
rCnt = rCnt + 2
Range("A1").Cells(rCnt, 1).Value = myFldrs.path: Range("A1").Cells(rCnt, CopyNumber).Offset(0, 2).Value = myFldrs.Name:
''''''''End doing stuff for each Folder
Dim oFile As Object
For Each oFile In myFldrs.Files
''''''''Doing Stuff for Each File
rCnt = rCnt + 1
Range("A1").Cells(rCnt, CopyNumber).Offset(0, 2).Value = oFile.Name
''''''''End Doing Sttuff for Each File
Next
Call EFLoopThroughEachFolderAndItsFile(myFldrs, rCnt, CopyNumber + 1)
Next
End Sub
_....................
Alan
Bookmarks