bsharath
asked on
Create a report file of all the shared folders in a machine with each extension as header and the count of objects in it.
Hi,
Create a report file of all the shared folders in a machine with each extension as header and the count of objects in it.
Any way a script can create a report of the shared folders.
like
jpeg c:\foldername\ 45 files
gif d:\mpf 60 files
According to folders and extension types i need the report.
Regards
Sharath
Create a report file of all the shared folders in a machine with each extension as header and the count of objects in it.
Any way a script can create a report of the shared folders.
like
jpeg c:\foldername\ 45 files
gif d:\mpf 60 files
According to folders and extension types i need the report.
Regards
Sharath
ASKER
Thanks for the response...
I am not getting any results when run...
I should be able to get results of any extension.All extension totals has to be mentioned..
I am not getting any results when run...
I should be able to get results of any extension.All extension totals has to be mentioned..
> I am not getting any results ..
my cristall ball does not show me your version/language of cmd.exe etc. But I assume that you have to replace Bytes by the correct word you get when you do a simpl dir in the line tellung you how much files there're and how many bytes, probaly just replace it by bytes
Also you have to run that command after doing something like
C:
cd mpf
> to get results of any extension
first I want to know if the provided for command returns the result you're interested in, then we can improve it for example to reduce it to just the line you need, and then I'll ask you what you mean by "any extension" and all extensions" (which I can assume again, buts it's very vage too:)
my cristall ball does not show me your version/language of cmd.exe etc. But I assume that you have to replace Bytes by the correct word you get when you do a simpl dir in the line tellung you how much files there're and how many bytes, probaly just replace it by bytes
Also you have to run that command after doing something like
C:
cd mpf
> to get results of any extension
first I want to know if the provided for command returns the result you're interested in, then we can improve it for example to reduce it to just the line you need, and then I'll ask you what you mean by "any extension" and all extensions" (which I can assume again, buts it's very vage too:)
Sharath, if you try this script on a smallish test folder, it will count the amount of each extension in each folder, and output to CSV:
'=================
Const FOLDER_PATH = "C:\Temp\Temp"
Const OUTPUT_FILE = "FileExtensionCount.csv"
Set objFSO = CreateObject("Scripting.Fi leSystemOb ject")
strResults = """Folder"",""File Extension"",""Amount"""
Set objFileTypes = CreateObject("Scripting.Di ctionary")
For Each objFile In objFSO.GetFolder(FOLDER_PA TH).Files
strExtension = LCase(objFSO.GetExtensionN ame(objFil e.Path))
If objFileTypes.Exists(FOLDER _PATH & ";" & strExtension) Then
objFileTypes(FOLDER_PATH & ";" & strExtension) = Int(objFileTypes(FOLDER_PA TH & ";" & strExtension)) + Int(1)
Else
objFileTypes.Add FOLDER_PATH & ";" & strExtension, Int(1)
End If
Next
For Each objSubFolder In objFSO.GetFolder(FOLDER_PA TH).SubFol ders
Recurse_SubFolder objSubFolder
Next
For Each strPathExt in objFileTypes
strPath = Split(strPathExt, ";")(0)
strExt = Split(strPathExt, ";")(1)
'WScript.Echo strExtension & " - " & objFileTypes(strExtension)
strResults = strResults & VbCrLf & """" & strPath & """,""" & strExt & """,""" & Int(objFileTypes(strPathEx t)) & """"
Next
Set objFileTypes = Nothing
Set objOutputFile = objFSO.CreateTextFile(OUTP UT_FILE, True)
objOutputFile.Write strResults
objOutputFile.Close
Set objOutputFile = Nothing
Set objFolder = Nothing
Set objFSO = Nothing
MsgBox "Done. Please see " & OUTPUT_FILE
' RECURSE SUB ROUTINE
Sub Recurse_SubFolder(objFolde r)
For Each objFile In objFolder.Files
strExtension = LCase(objFSO.GetExtensionN ame(objFil e.Path))
If objFileTypes.Exists(objFol der.Path & ";" & strExtension) Then
objFileTypes(objFolder.Pat h & ";" & strExtension) = Int(objFileTypes(objFolder .Path & ";" & strExtension)) + Int(1)
Else
objFileTypes.Add objFolder.Path & ";" & strExtension, Int(1)
End If
Next
For Each objSubFolder In objFolder.SubFolders
Recurse_SubFolder objSubFolder
Next
End Sub
'=================
Regards,
Rob.
'=================
Const FOLDER_PATH = "C:\Temp\Temp"
Const OUTPUT_FILE = "FileExtensionCount.csv"
Set objFSO = CreateObject("Scripting.Fi
strResults = """Folder"",""File Extension"",""Amount"""
Set objFileTypes = CreateObject("Scripting.Di
For Each objFile In objFSO.GetFolder(FOLDER_PA
strExtension = LCase(objFSO.GetExtensionN
If objFileTypes.Exists(FOLDER
objFileTypes(FOLDER_PATH & ";" & strExtension) = Int(objFileTypes(FOLDER_PA
Else
objFileTypes.Add FOLDER_PATH & ";" & strExtension, Int(1)
End If
Next
For Each objSubFolder In objFSO.GetFolder(FOLDER_PA
Recurse_SubFolder objSubFolder
Next
For Each strPathExt in objFileTypes
strPath = Split(strPathExt, ";")(0)
strExt = Split(strPathExt, ";")(1)
'WScript.Echo strExtension & " - " & objFileTypes(strExtension)
strResults = strResults & VbCrLf & """" & strPath & """,""" & strExt & """,""" & Int(objFileTypes(strPathEx
Next
Set objFileTypes = Nothing
Set objOutputFile = objFSO.CreateTextFile(OUTP
objOutputFile.Write strResults
objOutputFile.Close
Set objOutputFile = Nothing
Set objFolder = Nothing
Set objFSO = Nothing
MsgBox "Done. Please see " & OUTPUT_FILE
' RECURSE SUB ROUTINE
Sub Recurse_SubFolder(objFolde
For Each objFile In objFolder.Files
strExtension = LCase(objFSO.GetExtensionN
If objFileTypes.Exists(objFol
objFileTypes(objFolder.Pat
Else
objFileTypes.Add objFolder.Path & ";" & strExtension, Int(1)
End If
Next
For Each objSubFolder In objFolder.SubFolders
Recurse_SubFolder objSubFolder
Next
End Sub
'=================
Regards,
Rob.
ASKER
Excellent Rob this is exactly what i wanted.But any way it can scan just the shared folders instead of me providing each path
There should be. Will you be running this on one computer with shared folders, or against a few computers?
Rob.
Rob.
ASKER
Its going to be on a remote machines shared folders.If possible then multiple machines is helpful..
OK, try this. It is going to create one CSV file per shared folder, that does NOT end with a $ character. Otherwise that would include C$ and IPC$ shares, which would check the entire drive.
This could take a VERY long time, so try it with servers with very few shares first, in Servers_With_Shares.txt
'====================
Set objFSO = CreateObject("Scripting.Fi leSystemOb ject")
Const intForReading = 1
Const strInputFile = "Servers_With_Shares.txt"
Set objInputFile = objFSO.OpenTextFile(strInp utFile, intForReading, False)
While Not objInputFile.AtEndOfStream
strServer = objInputFile.ReadLine
Set objWMIService = GetObject("winmgmts:\\" & strServer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
("Select * From Win32_Share")
For Each objItem in colItems
If objItem.Type = 0 And Right(objItem.Name, 1) <> "$" Then
strPath = "\\" & strServer & "\" & Replace(objItem.Path, ":", "$")
strFileName = strServer & "_" & objItem.Name & "_Extension_List.csv"
strResults = """Folder"",""File Extension"",""Amount"""
Set objFileTypes = CreateObject("Scripting.Di ctionary")
Count_Extensions strPath
For Each strPathExt in objFileTypes
strPath = Split(strPathExt, ";")(0)
strExt = Split(strPathExt, ";")(1)
'WScript.Echo strExtension & " - " & objFileTypes(strExtension)
strResults = strResults & VbCrLf & """" & strPath & """,""" & strExt & """,""" & Int(objFileTypes(strPathEx t)) & """"
Next
Set objFileTypes = Nothing
Set objOutputFile = objFSO.CreateTextFile(strF ileName, True)
objOutputFile.Write strResults
objOutputFile.Close
Set objOutputFile = Nothing
Set objFolder = Nothing
'MsgBox "Done. Please see " & strFileName
End If
Next
Wend
objInputFile.Close
MsgBox "Script has finished going through servers."
Set objFSO = Nothing
WScript.Quit
Sub Count_Extensions(FOLDER_PA TH)
For Each objFile In objFSO.GetFolder(FOLDER_PA TH).Files
strExtension = LCase(objFSO.GetExtensionN ame(objFil e.Path))
If objFileTypes.Exists(FOLDER _PATH & ";" & strExtension) Then
objFileTypes(FOLDER_PATH & ";" & strExtension) = Int(objFileTypes(FOLDER_PA TH & ";" & strExtension)) + Int(1)
Else
objFileTypes.Add FOLDER_PATH & ";" & strExtension, Int(1)
End If
Next
For Each objSubFolder In objFSO.GetFolder(FOLDER_PA TH).SubFol ders
Recurse_SubFolder objSubFolder
Next
End Sub
' RECURSE SUB ROUTINE
Sub Recurse_SubFolder(objFolde r)
For Each objFile In objFolder.Files
strExtension = LCase(objFSO.GetExtensionN ame(objFil e.Path))
If objFileTypes.Exists(objFol der.Path & ";" & strExtension) Then
objFileTypes(objFolder.Pat h & ";" & strExtension) = Int(objFileTypes(objFolder .Path & ";" & strExtension)) + Int(1)
Else
objFileTypes.Add objFolder.Path & ";" & strExtension, Int(1)
End If
Next
For Each objSubFolder In objFolder.SubFolders
Recurse_SubFolder objSubFolder
Next
End Sub
'====================
Regards,
Rob.
This could take a VERY long time, so try it with servers with very few shares first, in Servers_With_Shares.txt
'====================
Set objFSO = CreateObject("Scripting.Fi
Const intForReading = 1
Const strInputFile = "Servers_With_Shares.txt"
Set objInputFile = objFSO.OpenTextFile(strInp
While Not objInputFile.AtEndOfStream
strServer = objInputFile.ReadLine
Set objWMIService = GetObject("winmgmts:\\" & strServer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
("Select * From Win32_Share")
For Each objItem in colItems
If objItem.Type = 0 And Right(objItem.Name, 1) <> "$" Then
strPath = "\\" & strServer & "\" & Replace(objItem.Path, ":", "$")
strFileName = strServer & "_" & objItem.Name & "_Extension_List.csv"
strResults = """Folder"",""File Extension"",""Amount"""
Set objFileTypes = CreateObject("Scripting.Di
Count_Extensions strPath
For Each strPathExt in objFileTypes
strPath = Split(strPathExt, ";")(0)
strExt = Split(strPathExt, ";")(1)
'WScript.Echo strExtension & " - " & objFileTypes(strExtension)
strResults = strResults & VbCrLf & """" & strPath & """,""" & strExt & """,""" & Int(objFileTypes(strPathEx
Next
Set objFileTypes = Nothing
Set objOutputFile = objFSO.CreateTextFile(strF
objOutputFile.Write strResults
objOutputFile.Close
Set objOutputFile = Nothing
Set objFolder = Nothing
'MsgBox "Done. Please see " & strFileName
End If
Next
Wend
objInputFile.Close
MsgBox "Script has finished going through servers."
Set objFSO = Nothing
WScript.Quit
Sub Count_Extensions(FOLDER_PA
For Each objFile In objFSO.GetFolder(FOLDER_PA
strExtension = LCase(objFSO.GetExtensionN
If objFileTypes.Exists(FOLDER
objFileTypes(FOLDER_PATH & ";" & strExtension) = Int(objFileTypes(FOLDER_PA
Else
objFileTypes.Add FOLDER_PATH & ";" & strExtension, Int(1)
End If
Next
For Each objSubFolder In objFSO.GetFolder(FOLDER_PA
Recurse_SubFolder objSubFolder
Next
End Sub
' RECURSE SUB ROUTINE
Sub Recurse_SubFolder(objFolde
For Each objFile In objFolder.Files
strExtension = LCase(objFSO.GetExtensionN
If objFileTypes.Exists(objFol
objFileTypes(objFolder.Pat
Else
objFileTypes.Add objFolder.Path & ";" & strExtension, Int(1)
End If
Next
For Each objSubFolder In objFolder.SubFolders
Recurse_SubFolder objSubFolder
Next
End Sub
'====================
Regards,
Rob.
ASKER
I get this..
-------------------------- -
Windows Script Host
-------------------------- -
Script: C:\Shares search extension.vbs
Line: 46
Char: 7
Error: Path not found
Code: 800A004C
Source: Microsoft VBScript runtime error
-------------------------- -
OK
-------------------------- -
--------------------------
Windows Script Host
--------------------------
Script: C:\Shares search extension.vbs
Line: 46
Char: 7
Error: Path not found
Code: 800A004C
Source: Microsoft VBScript runtime error
--------------------------
OK
--------------------------
Change the Count_Extensions(FOLDER_PA TH) to this:
Sub Count_Extensions(FOLDER_PA TH)
If objFSO.FolderExists(FOLDER _PATH) = True Then
For Each objFile In objFSO.GetFolder(FOLDER_PA TH).Files
strExtension = LCase(objFSO.GetExtensionN ame(objFil e.Path))
If objFileTypes.Exists(FOLDER _PATH & ";" & strExtension) Then
objFileTypes(FOLDER_PATH & ";" & strExtension) = Int(objFileTypes(FOLDER_PA TH & ";" & strExtension)) + Int(1)
Else
objFileTypes.Add FOLDER_PATH & ";" & strExtension, Int(1)
End If
Next
For Each objSubFolder In objFSO.GetFolder(FOLDER_PA TH).SubFol ders
Recurse_SubFolder objSubFolder
Next
Else
MsgBox "Could not find " & FOLDER_PATH
End If
End Sub
Regards,
Rob.
Sub Count_Extensions(FOLDER_PA
If objFSO.FolderExists(FOLDER
For Each objFile In objFSO.GetFolder(FOLDER_PA
strExtension = LCase(objFSO.GetExtensionN
If objFileTypes.Exists(FOLDER
objFileTypes(FOLDER_PATH & ";" & strExtension) = Int(objFileTypes(FOLDER_PA
Else
objFileTypes.Add FOLDER_PATH & ";" & strExtension, Int(1)
End If
Next
For Each objSubFolder In objFSO.GetFolder(FOLDER_PA
Recurse_SubFolder objSubFolder
Next
Else
MsgBox "Could not find " & FOLDER_PATH
End If
End Sub
Regards,
Rob.
ASKER
I get this Rob..
-------------------------- -
Windows Script Host
-------------------------- -
Script: C:\Shares search extension.vbs
Line: 56
Char: 13
Error: Type mismatch: 'Recurse_SubFolder'
Code: 800A000D
Source: Microsoft VBScript runtime error
-------------------------- -
OK
-------------------------- -
--------------------------
Windows Script Host
--------------------------
Script: C:\Shares search extension.vbs
Line: 56
Char: 13
Error: Type mismatch: 'Recurse_SubFolder'
Code: 800A000D
Source: Microsoft VBScript runtime error
--------------------------
OK
--------------------------
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Rob the csv is created but no data in it...
I get this...
-------------------------- -
-------------------------- -
Could not find \\dev-chen-mrd1\F$\Indlist old
-------------------------- -
OK
-------------------------- -
I get this...
--------------------------
--------------------------
Could not find \\dev-chen-mrd1\F$\Indlist
--------------------------
OK
--------------------------
Hmmmm....can you browse to a folder with that "exact" name? Or is that the share name, rather than the actual folder name?
You should be able to click Start --> Run, type in
\\dev-chen-mrd1\F$\Indlist old
and display that folder.....
Aside from that though, it should be creating at least a few files, called
<<SERVERNAM>>_<<SHARENAME> >_Extensio n_List.csv
Regards,
Rob.
You should be able to click Start --> Run, type in
\\dev-chen-mrd1\F$\Indlist
and display that folder.....
Aside from that though, it should be creating at least a few files, called
<<SERVERNAM>>_<<SHARENAME>
Regards,
Rob.
ASKER
Rob
When i access this like this..
\\dev-chen-mrd1\F$\Indlist old
Does not work
If i access like this it opens..
\\dev-chen-mrd1\Indlist old
As i am running from a remote machine the F$ should not be accessed..
When i access this like this..
\\dev-chen-mrd1\F$\Indlist
Does not work
If i access like this it opens..
\\dev-chen-mrd1\Indlist old
As i am running from a remote machine the F$ should not be accessed..
OK then, change this:
strPath = "\\" & strServer & "\" & Replace(objItem.Path, ":", "$")
to this:
strPath = "\\" & strServer & "\" & objItem.Name
Regards,
Rob.
strPath = "\\" & strServer & "\" & Replace(objItem.Path, ":", "$")
to this:
strPath = "\\" & strServer & "\" & objItem.Name
Regards,
Rob.
ASKER
Sorry for the delay i tested it on a big share..
Works great Rob...
Works great Rob...
ASKER
Thanks Rob...
No problem. Yeah, it takes a while!
Rob.
Rob.
ASKER
Rob can you have a quick glance on this please...
https://www.experts-exchange.com/questions/23122257/Data-convert-to-Colum-from-the-data-in-excel-and-send-mail-to-each.html
https://www.experts-exchange.com/questions/23122257/Data-convert-to-Colum-from-the-data-in-excel-and-send-mail-to-each.html
for /f "tokens=1,2,3,4" %a in ('dir /s *.gif') do @if %d==Bytes echo gif %a %b