Need a script to scan network drive for folders and subfolders 1 level deep

Microsoft Windows
Post Reply
User avatar
MigrationUser
Posts: 336
Joined: 2021-Jul-12, 1:37 pm
Contact:

Need a script to scan network drive for folders and subfolders 1 level deep

Post by MigrationUser »

27 Nov 2012 14:02
hondo008

I need to scan a Shared drive on the network for folder and sub-folder information.

There are multiple folders (@ 75) and each folder has at least 3 sub directories. (\Private, \Public , \Shared)

I need a script which will give me a text file with each folder with sub folder. ( ie

\\Shared\Folder1\Private
\\Shared\Folder1\Public
\\Shared\Folder1\Shared

\\Shared\Folder2\Private
\\Shared\Folder2\Public
\\Shared\Folder2\Shared

Etc

I am trying to speed up backups and it helps with the Share broken out like this.
Thanks any help and your time.
Hondo

----------------------------

#2 27 Nov 2012 15:37
bluesxman

Code: Select all

@echo off
for /d %%a in ("\\Shared\*") do (
    for /d %%b in ("%%~a\*") do (
        (set /p "out=%%~b" <nul & echo:) >> yourList.txt
    )
)
cmd | *sh | ruby | chef

----------------------------

#3 28 Nov 2012 18:29
hondo008


Thank you works like a champ.

----------------------------

#4 30 Nov 2012 14:23
hondo008


Thanks for your script the other day. It worked very well and easy. I have one last question. Can an exclusion be added to this to bypass one or two folders? This would help on balancing out folders due to size.

Again, I appreicate your help and time.

Hondo

----------------------------

#5 30 Nov 2012 22:10
RG


Modified to exclude a couple of folders. If these change frequently or you have more than a couple you might want to have a list of folders to exclude in an ExcludeFolders.txt file... but this will work fine for what you asked.
I added the second line to delete yourList.txt if it exists to avoid appending to an existing file. Your choice as to whether you want that.
Added 2 case insensitive find commands that will skip folders. May not always need full path, but it is safest in case specified string is a substring within one that you really did not want to delete :)

Code: Select all

@echo off
if exist "yourList.txt" del /q "yourList.txt"
for /d %%a in ("\\Shared\*") do (
    for /d %%b in ("%%~a\*") do (
        (set /p "out=%%~b" <nul & echo:) | find /i /v "PathOfFolderToExclude" | find /i /v "PathOfAnotherFolderToExclude" >> yourList.txt
    )
)
Windows Shell Scripting and InstallShield

----------------------------

#6 13 Dec 2012 19:24
hondo008


Thank you, works very good.
Post Reply