R
rac8006
Guest
I'm new to vista and vbscript. But I created the following script to display
the size of folders in a directory.
When I run the program from a cmd window that has been started with run as
administrator it get permission denied on the c:\windows\system32 directory
when I enter c:\windows. If I enter c: the users and windows directories get
permission denied. I also get the same problem if I login as administrator.
What am I doing wrong?
I used the following vbscript:
Const ForWriting = 1
Dim arrHeaders(48),fso,ts,file2
Int sz
Set fso = CreateObject("Scripting.FileSystemObject")
Sub ShowFolderSize(filespec)
On Error Resume Next
Dim fs, f, s
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(filespec)
n = int(f.size)
If Err.Number <> 0 Then
MsgBox Err.Number & ": " & Err.Description & filespec
Err.Clear
End If
sz = sz + n
n = FormatNumber(n,False,False,-1)
s = UCase(f.Name) & Space(30 - Len(f.Name)) & "uses " & Space(18-Len)
& n & " bytes."
str = str & s & vbcrlf
End Sub
Function Search(Dir)
Set objShell = CreateObject("Shell.Application")
Set objfolder = objShell.Namespace(Dir)
For Each strFileName in objFolder.Items
If fso.FolderExists(Dir & "\" & strFileName) = True Then
ShowFolderSize(Dir & "\" & strFileName)
End If
next
str = str & vbcrlf
End Function
set file2 = fso.CreateTextFile("C:\temp\filelst.txt", ForWriting, True)
str = ""
str1 = InputBox("Enter directory?")
Search(str1)
sz = FormatNumber(sz,False,False,-1)
str = str & vbcrlf & "Total bytes " & sz
wscript.Echo str
file2.write(str)
file2.close
the size of folders in a directory.
When I run the program from a cmd window that has been started with run as
administrator it get permission denied on the c:\windows\system32 directory
when I enter c:\windows. If I enter c: the users and windows directories get
permission denied. I also get the same problem if I login as administrator.
What am I doing wrong?
I used the following vbscript:
Const ForWriting = 1
Dim arrHeaders(48),fso,ts,file2
Int sz
Set fso = CreateObject("Scripting.FileSystemObject")
Sub ShowFolderSize(filespec)
On Error Resume Next
Dim fs, f, s
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(filespec)
n = int(f.size)
If Err.Number <> 0 Then
MsgBox Err.Number & ": " & Err.Description & filespec
Err.Clear
End If
sz = sz + n
n = FormatNumber(n,False,False,-1)
s = UCase(f.Name) & Space(30 - Len(f.Name)) & "uses " & Space(18-Len)
& n & " bytes."
str = str & s & vbcrlf
End Sub
Function Search(Dir)
Set objShell = CreateObject("Shell.Application")
Set objfolder = objShell.Namespace(Dir)
For Each strFileName in objFolder.Items
If fso.FolderExists(Dir & "\" & strFileName) = True Then
ShowFolderSize(Dir & "\" & strFileName)
End If
next
str = str & vbcrlf
End Function
set file2 = fso.CreateTextFile("C:\temp\filelst.txt", ForWriting, True)
str = ""
str1 = InputBox("Enter directory?")
Search(str1)
sz = FormatNumber(sz,False,False,-1)
str = str & vbcrlf & "Total bytes " & sz
wscript.Echo str
file2.write(str)
file2.close