Counting the Number of Subdirectory Levels

I was using a program called wget to create a backup, on my hard drive, of the contents of my blogs. I wanted to see how deep this backup went. That is, I could see that wget was creating subfolders, and sub-subfolders, and sub-sub-folders, two and three and more layers deep. There were thousands of folders. I couldn’t open them all manually, to see how deep the deepest one went. This post describes how I found the answer.

I started with a command on the Windows (sometimes called DOS) command line. This was the command I used:

dir /ad /b /s > D:\dirlist.txt

Then I opened dirlist.txt to see what the command had given me. Here is the kind of output I saw there:


In that example, the deepest folder (“amp”) was six levels below the top (D:) level. But, again, I had thousands of folders. So I pasted the contents of dirlist.txt into an Excel spreadsheet, starting with cell A1. Then I wrote a formula to count the number of levels. Here is the Excel formula I used:


I copied that formula all the way down, to count the number of levels for every subfolder. Finally, at the bottom, I used Excel’s MAX function to find the deepest level.

This entry was posted in Uncategorized and tagged , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s