So you only want to list the number of 2nd level folders, but not 1st or 3rd? And list number of files for all folders?
Would
E:\Backup be the 1st level, or
E:\Backup\Folder_X?
You can list Number of folders for each folder easily, but trying to determine the Level of the current folder would complicate things. And sounds like you want to list them in "Tree Order", rather than "Level Order"
The Dir command lists folders in "Level order"; it first lists all the top level folders, then all the 2nd level folders, then all the 3rd level folders, etc, like this:
Code:
Parent 1st Level 2nd Level 3rd Level
C:\Test Dir\Folder 1
C:\Test Dir\Folder 2
C:\Test Dir\Folder 3
C:\Test Dir\Folder 4
C:\Test Dir\Folder 1\Fldr1Sub1
C:\Test Dir\Folder 1\Fldr1Sub2
C:\Test Dir\Folder 1\Fldr1Sub1\Fldr1SubSub1
C:\Test Dir\Folder 2\Fldr2Sub1
C:\Test Dir\Folder 2\Fldr2Sub1\Fldr2SubSub1
If you want to list them in "Tree order", that gets even more complicated.
By "Tree order" I mean listing them in this order:
Code:
C:\TEST DIR
├───Folder 1
│ ├───Fldr1Sub1
│ │ └───Fldr1SubSub1
│ └───Fldr1Sub2
├───Folder 2
│ └───Fldr2Sub1
│ └───Fldr2SubSub1
├───Folder 3
└───Folder 4
Or in Text:
C:\Test Dir\Folder 1
C:\Test Dir\Folder 1\Fldr1Sub1
C:\Test Dir\Folder 1\Fldr1Sub1\Fldr1SubSub1
C:\Test Dir\Folder 1\Fldr1Sub2
C:\Test Dir\Folder 2
C:\Test Dir\Folder 2\Fldr2Sub1
C:\Test Dir\Folder 2\Fldr2Sub1\Fldr2SubSub1
C:\Test Dir\Folder 3
C:\Test Dir\Folder 4
Might be a whole lot easier to let the backup program create a list of files that it copied. What are you using to do the backup?
If you are using Robocopy to do the actual backup, it can easily create a log of the files it copies, which will show the Source path, rather than the Backup path.
And it will generate the list in Tree Order, rather than Level Order. The output will show the total files in each folder, so you would have to do some counting to count only the files that were copied, but not to hard to do, as you would only be parsing the log file, instead of actually doing Dir commands.
Another option is to use Robocopy to generate a list of files that are not more than 1 day old, this will show the path in the Backup tree rather than the Source tree.
This will list the number of subfolders in each folder, along with the number of files:
Code:
@Echo Off
Setlocal EnableDelayedExpansion
Set _Src=E:\Backup\Data
Set _OutPut=%_Src%\list.txt
Set _tmp=%_Src%\del1.txt
Echo Wscript.Echo ^(Date^(^)- 1^)>yesterday.vbs
For /F %%a In ('cscript //nologo yesterday.vbs') Do Set ydate1=%%a
Del yesterday.vbs
Set ydate1=%ydate1:/=%
Set d=%ydate1:~0,2%
Set m=%ydate1:~2,2%
Set y=%ydate1:~4,4%
Set ydate2=%d%/%m%/%y%
>"%_OutPut%" Echo Good morning, here is backup 2 yesterdays (%ydate2%) list. . .
>>"%_OutPut%" Echo.
For /F "Tokens=*" %%I In ('Dir "%_Src%" /AD /B /ON /S') Do (
If Exist "%_tmp%" Del "%_tmp%"
PushD "%%I"
Set _Count=0
For /F "tokens=1" %%A In ('Dir /AD') Do Set /A _Fldrs=%%A-2
For /F "tokens=*" %%A In ('Dir /A-D /OD^|Findstr "%ydate2%"') Do (
>>"%_tmp%" Echo %%A
Set /A _Count+=1
)
PopD
If !_Fldrs! GTR 0 If !_Count! GTR 0 >>"%_OutPut%" Echo %%I -- Number of Folders = !_Fldrs!
If !_Count! GTR 0 (
>>"%_OutPut%" Echo %%I -- Number of Files = !_Count!
>>"%_OutPut%" Type "%_tmp%"
>>"%_OutPut%" Echo.
))
If Exist "%_tmp%" Del "%_tmp%"
And for
PushDirectory and
PopDirectory type the command followed by
/? for help:
Code:
C:\>pushD /?
Stores the current directory for use by the POPD command, then
changes to the specified directory.
PUSHD [path | ..]
path Specifies the directory to make the current directory.
If Command Extensions are enabled the PUSHD command accepts
network paths in addition to the normal drive letter and path.
If a network path is specified, PUSHD will create a temporary
drive letter that points to that specified network resource and
then change the current drive and directory, using the newly
defined drive letter. Temporary drive letters are allocated from
Z: on down, using the first unused drive letter found.
C:\>PopD /?
Changes to the directory stored by the PUSHD command.
POPD
If Command Extensions are enabled the POPD command will delete
any temporary drive letter created by PUSHD when you POPD that
drive off the pushed directory stack.