sammy2ooo 10 Geschrieben 6. Juni 2008 Melden Teilen Geschrieben 6. Juni 2008 Situation: Homefolderstruktur der User: e:\userfolder\user_a\documentse:\userfolder\user_a\outlook_Archive e:\userfolder\user_a\... e:\userfolder\user_b\documents e:\userfolder\user_b\outlook_Archive e:\userfolder\user_b\... e:\userfolder\user_c\documents e:\userfolder\user_c\outlook_Archive e:\userfolder\user_c\... Alle Word, Excel, PDFs, MP3s etc. liegen unter "documents" Aufgabe: Finde heraus wieviel Speicherplatz (Prozent) bei einem allgemeinem Speicherverbrauch von über 500MB für Bilder, Videos und Musik verwendet wird. :confused: Die Ansprüche der Vorgesetzten steigen... Hiermal ein Script mit welchem ich den allgemeinen Speicherplatzverbrauch pro User im Ordner "documents" ermitteln kann: rootFolder = "e:\userdata" destFile = "e:\output.txt" Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFolders = objFSO.GetFolder(rootFolder) For Each objFolder In objFolders.SubFolders If objFSO.FolderExists(objFolder.path & "\documents") Then Set objCurrentFolder = objFSO.GetFolder(objFolder.path & "\documents") ' get folder size (recursive) Foldersize = objCurrentFolder.Size ' construct data data = objCurrentFolder.Path & vbTab & vbTab & vbTab & vbTab & Round(FolderSize/1024/1024) & " MB" WScript.Echo data ' write data to file Call append(destFile, data) ' reset var FolderSize = 0 End If Next Sub append(ByVal file, ByVal text) Const forReading = 1 Const forWrting = 2 Const debug = False Set objFSO = CreateObject("Scripting.FileSystemObject") ' wenns datei schon gibt If objFSO.FileExists(file) Then if debug then WScript.Echo "append: appending to: " + file Set objTemp = objFSO.GetFile(file) if objTemp.Size <> 0 Then if debug then WScript.Echo "append: file size is not zero!" ' datei ist nicht leer, also lies inhalt Set objTextFile = objFSO.OpenTextFile(file, forReading) ' read file till end Do Until objTextFile.AtEndOfStream strContents = objTextFile.ReadAll Loop ' close file in reading mode objTextFile.Close ' open file in writing mode Set objTextFile = objFSO.OpenTextFile(file, forWrting) ' und fuege content an strContents = strContents & VbCrLf & text ' schreibe content objTextFile.Write(strContents) ' schliesse file objTextFile.Close Else if debug then WScript.Echo "append: file is empty..." ' file ist leer Set objTextFile = objFSO.OpenTextFile(file, forWrting) strContents = text ' schreibe content objTextFile.Write(strContents) ' schliesse file objTextFile.Close End If Else if debug Then WScript.Echo "append: file does not exist, creating..." ' ansonten file anlegen objFSO.CreateTextFile(file) ' im write mode öffnen Set objTextFile = objFSO.OpenTextFile(file, forWrting) ' string schreiben objTextFile.Write(text) ' file wieder schliessen objTextFile.Close End If End Sub Gibts vielleicht schon ein Tool oder Script, mit welchem man diese Aufgabe bewältigen kann? Treesize und Konsorten hab ich bereits durch... Ich kann mich erinnern mal etwas über VBScript Filter gelesen zu haben, hab davon allerdings kein Plan... kann mir jemand einen Schubs in die richtige Richtung geben? Generel scheint das ein Feature zu sein, was noch im Performance Snapin fehlt... Zitieren Link zu diesem Kommentar
Caddy24 10 Geschrieben 6. Juni 2008 Melden Teilen Geschrieben 6. Juni 2008 Du schreibst, Du hast Treesize schon angeschaut, hast Du auch die Pro Version gesehen? Die liefert dir nämlich schöne Analysen nach Dateityp/Dateitypgruppen (Videos, Musik, Bilder)/ Auflistung der 100 größten Dateien usw. Zitieren Link zu diesem Kommentar
sammy2ooo 10 Geschrieben 6. Juni 2008 Autor Melden Teilen Geschrieben 6. Juni 2008 Hier die Lösung, nicht schön aber funktioniell... hab jetzt 5 graue Haare mehr... Teil 1 rootFolder = "c:\temp" destFile = "C:\output.txt" Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFolders = objFSO.GetFolder(rootFolder) debugTest = False For Each objFolder In objFolders.SubFolders If objFSO.FolderExists(objFolder.path & "\documents") Then Set objCurrentFolder = objFSO.GetFolder(objFolder.path & "\documents") ' get folder size (recursive) Foldersize = objCurrentFolder.Size sndFileResultSize = CheckFolder(objCurrentFolder, "sound", 0) vidFileResultSize = CheckFolder(objCurrentFolder, "video", 0) picFileResultSize = CheckFolder(objCurrentFolder, "picture", 0) ' construct data data = objCurrentFolder.Path & vbTab & vbTab & Round(FolderSize/1024/1024) & " MB -> 100 %" & VbCrLf &_ "PicSize: " & vbTab & vbTab & vbTab & Round(picFileResultSize/1024/1024) & " MB -> " & Round(Round(picFileResultSize/1024/1024)/(100/(Foldersize/1024/1024))) & " %" & VbCrLf &_ "SndSize: " & vbTab & vbTab & vbTab & Round(sndFileResultSize/1024/1024) & " MB -> " & Round(Round(sndFileResultSize/1024/1024)/(100/(Foldersize/1024/1024))) & " %" & VbCrLf &_ "VidSize: " & vbTab & vbTab & vbTab & Round(vidFileResultSize/1024/1024) & " MB -> " & Round(Round(vidFileResultSize/1024/1024)/(100/(Foldersize/1024/1024))) & " %" & VbCrLf WScript.Echo data ' write data to file append destFile, data ' reset var FolderSize = 0 End If Next – Teil 2 Sub append(ByVal file, ByVal text) Const forReading = 1 Const forWrting = 2 Const debug = False Set objFSO = CreateObject("Scripting.FileSystemObject") ' wenns datei schon gibt If objFSO.FileExists(file) Then if debug then WScript.Echo "append: appending to: " + file Set objTemp = objFSO.GetFile(file) if objTemp.Size <> 0 Then if debug then WScript.Echo "append: file size is not zero!" ' datei ist nicht leer, also lies inhalt Set objTextFile = objFSO.OpenTextFile(file, forReading) ' read file till end Do Until objTextFile.AtEndOfStream strContents = objTextFile.ReadAll Loop ' close file in reading mode objTextFile.Close ' open file in writing mode Set objTextFile = objFSO.OpenTextFile(file, forWrting) ' und fuege content an strContents = strContents & VbCrLf & text ' schreibe content objTextFile.Write(strContents) ' schliesse file objTextFile.Close Else if debug then WScript.Echo "append: file is empty..." ' file ist leer Set objTextFile = objFSO.OpenTextFile(file, forWrting) strContents = text ' schreibe content objTextFile.Write(strContents) ' schliesse file objTextFile.Close End If Else if debug Then WScript.Echo "append: file does not exist, creating..." ' ansonten file anlegen objFSO.CreateTextFile(file) ' im write mode öffnen Set objTextFile = objFSO.OpenTextFile(file, forWrting) ' string schreiben objTextFile.Write(text) ' file wieder schliessen objTextFile.Close End If End Sub Zitieren Link zu diesem Kommentar
sammy2ooo 10 Geschrieben 6. Juni 2008 Autor Melden Teilen Geschrieben 6. Juni 2008 Teil 3 Function CheckFolder(objCurrentFolder, typeToCheck, currentSize) ' search for soundfiles and get size If typeToCheck = "sound" Then if debugTest Then WScript.Echo "Checking sound size..." For Each objFile In objCurrentFolder.Files If InStr(LCase(objFile.Name), LCase(".mp3")) Then if debugTest Then WScript.Echo "vid file found " & objFile.Name currentSize = currentSize + objFile.Size ElseIf InStr(LCase(objFile.Name), LCase(".wmv")) Then if debugTest then WScript.Echo "vid file found " & objFile.Name currentSize = currentSize + objFile.Size ElseIf InStr(LCase(objFile.Name), LCase(".wav")) Then if debugTest then WScript.Echo "vid file found " & objFile.Name currentSize = currentSize + objFile.Size ElseIf InStr(LCase(objFile.Name), LCase(".mp4")) Then if debugTest then WScript.Echo "vid file found " & objFile.Name currentSize = currentSize + objFile.Size End If Next For Each objNewFolder In objCurrentFolder.SubFolders If debugTest Then WScript.Echo CurrentSize If debugTest Then WScript.echo objNewFolder.Path CheckFolder objNewFolder, typeToCheck, currentSize Next CheckFolder = currentSize ' search for videos and get size ElseIf typeToCheck = "video" Then if debugTest Then WScript.Echo "Checking video size..." For Each objFile In objCurrentFolder.Files If InStr(LCase(objFile.Name), LCase(".avi")) Then if debugTest Then WScript.Echo "vid file found " & objFile.Name currentSize = currentSize + objFile.Size ElseIf InStr(LCase(objFile.Name), LCase(".mpg")) Then if debugTest Then WScript.Echo "vid file found " & objFile.Name currentSize = currentSize + objFile.Size ElseIf InStr(LCase(objFile.Name), LCase(".mpeg")) Then if debugTest then WScript.Echo "vid file found " & objFile.Name currentSize = currentSize + objFile.Size ElseIf InStr(LCase(objFile.Name), LCase(".mod")) Then if debugTest then WScript.Echo "vid file found " & objFile.Name currentSize = currentSize + objFile.Size End If Next For Each objNewFolder In objCurrentFolder.SubFolders If debugTest Then WScript.Echo CurrentSize If debugTest Then WScript.echo objNewFolder.Path CheckFolder objNewFolder, typeToCheck, currentSize Next CheckFolder = currentSize ......... Zitieren Link zu diesem Kommentar
sammy2ooo 10 Geschrieben 6. Juni 2008 Autor Melden Teilen Geschrieben 6. Juni 2008 Teil 4 ....................... ' search for pics and get size ElseIf typeToCheck = "picture" Then If debugTest Then WScript.Echo "Checking picture size..." For Each objFile In objCurrentFolder.Files If InStr(LCase(objFile.Name), LCase(".bmp")) Then if debugTest then WScript.Echo "pic file found " & objFile.Name currentSize = currentSize + objFile.Size ElseIf InStr(LCase(objFile.Name), LCase(".gif")) Then if debugTest then WScript.Echo "pic file found " & objFile.Name currentSize = currentSize + objFile.Size ElseIf InStr(LCase(objFile.Name), LCase(".jpg")) Then if debugTest then WScript.Echo "pic file found " & objFile.Name currentSize = currentSize + objFile.Size ElseIf InStr(LCase(objFile.Name), LCase(".jpeg")) Then if debugTest then WScript.Echo "pic file found " & objFile.Name currentSize = currentSize + objFile.Size ElseIf InStr(LCase(objFile.Name), LCase(".png")) Then if debugTest then WScript.Echo "pic file found " & objFile.Name currentSize = currentSize + objFile.Size ElseIf InStr(LCase(objFile.Name), LCase(".psd")) Then if debugTest then WScript.Echo "pic file found " & objFile.Name currentSize = currentSize + objFile.Size ElseIf InStr(LCase(objFile.Name), LCase(".eps")) Then if debugTest then WScript.Echo "pic file found " & objFile.Name currentSize = currentSize + objFile.Size ElseIf InStr(LCase(objFile.Name), LCase(".tif")) Then if debugTest then WScript.Echo "pic file found " & objFile.Name currentSize = currentSize + objFile.Size End If Next For Each objNewFolder In objCurrentFolder.SubFolders If debugTest Then WScript.Echo CurrentSize If debugTest Then WScript.echo objNewFolder.Path CheckFolder objNewFolder, typeToCheck, currentSize Next CheckFolder = currentSize Else WScript.Echo "Tpye not implemented..." WScript.Quit End If Zitieren Link zu diesem Kommentar
Empfohlene Beiträge
Schreibe einen Kommentar
Du kannst jetzt antworten und Dich später registrieren. Falls Du bereits ein Mitglied bist, logge Dich jetzt ein.