

There’s another complication, too, but we’ll deal with that in a minute. And then call itself again to access a sub-subfolder. In other words, if we have a function that accesses a folder and lists all its files, that function can call itself to access a subfolder and list all the files found there. Suffice to say that we’re creating a function that can call itself as many times as needed.
#How to list directory contents in windows windows#
Explaining recursion is a bit beyond what we can do in this column for a brief explanation, check out the Microsoft Windows 2000 Scripting Guide.

Because of that, we need to use a recursive function to perform this task. Second, we noted that none of the scripting technologies has a built-in way to iterate through a folder, list the file names, and then automatically iterate through any and all subfolders and list the files found there. That’s not the case with either the FileSystemObject or the Shell object. The resulting script is perhaps a little more complicated than a similar script using the FileSystemObject or the Shell object, but a WMI script that can retrieve this kind of information on the local computer can just as easily retrieve this kind of information from a remote computer. Any of these technologies will do the trick, but none will do it very easily. However, none of these technologies have a mechanism to automatically list the files in those subfolders (not to mention any sub-subfolders that might be found there).

WMI, the FileSystemObject, and the Shell object are all capable of listing the files in a folder, as well as listing the subfolders in a folder. First, we need to pick a scripting technology. On the other hand, the customer is always right: if you guys want a script that can list all the files in a folder, as well as all the files in any subfolders of that folder, well, who are we to argue?īefore we begin there are two issues we have to grapple with here. That’s because there is no nice, simple answer to this one: a script that can carry out this task is bound to be a little bit confusing, and isn’t going to lend itself to the easy-to-explain approach we like to take with this column. This is a question we get asked quite a bit, and one which have avoided answering up till now. Hey, Scripting Guy! How can I list all of the files in a folder, as well as all the files in any subfolders of that folder?
