i have a vbs to count number of doc files, like this
for each folder in folders .... next

the script is completely ok to count files in the folders with file rights
permission.

however, i try to run it in other folders without file rights, like
c:\documents and settings\OtherUser.... it has a script error

then i use "on error resume next" to try to bypass the folder

the script can be finished. but the count calculation is completely wrong.
funny is that it return result of 1732 doc files but i don't have permission
to look into the folder.

my question is how can i bypass the folder which i don't have file
permission.

my script is supposed to loop through all the folders in a drive.

Thanks a lot.

tony

Re: Bypass folders without file permissions by Pegasus

Pegasus
Thu Jun 26 05:57:06 CDT 2008


"Tony WONG" <x34@netvigator.com> wrote in message
news:e%23J9s121IHA.2068@TK2MSFTNGP05.phx.gbl...
>i have a vbs to count number of doc files, like this
> for each folder in folders .... next
>
> the script is completely ok to count files in the folders with file rights
> permission.
>
> however, i try to run it in other folders without file rights, like
> c:\documents and settings\OtherUser.... it has a script error
>
> then i use "on error resume next" to try to bypass the folder
>
> the script can be finished. but the count calculation is completely
> wrong. funny is that it return result of 1732 doc files but i don't have
> permission to look into the folder.
>
> my question is how can i bypass the folder which i don't have file
> permission.
>
> my script is supposed to loop through all the folders in a drive.
>
> Thanks a lot.
>
> tony

Sorry, can't tell without seeing your script.



Re: Bypass folders without file permissions by Tony

Tony
Thu Jun 26 20:59:54 CDT 2008

Hi Pegasus

here is the code. there is problem when touch with unauthorized folders.
******************************************************
dim Qword, Qexcel, Qaccess
Set objFSOc = CreateObject("Scripting.FileSystemObject")
set objdriveC = objFSOc.getfolder("C:\Documents and Settings")

Qword = 0
Qexcel = 0
Qaccess = 0

Countfiles(objdriveC)
msgbox(Qword & " - " & Qexcel & " - " & Qaccess)

sub Countfiles(objDrive)
on error resume next
for each objfolder in objDrive.subfolders
if objfolder.name <> "Program Files" and objfolder.name <> "Default User"
and objfolder.name <> "RECYCLER" and objfolder.name <> "All Users" and
objfolder.name <> "Media Player" and objfolder.name <> "System Volume
Information" and objfolder.name <> "NetworkService" and objfolder.name <>
"MSOCache" and objfolder.name <> "LocalService" then
set objfiles = objfolder.files
for each objfile in objfiles
if right(objfile.name, 3) = "doc" or right(objfile.name, 4) = "docx"
then
QWord = Qword + 1
elseif right(objfile.name, 3) = "xls" or right(objfile.name, 4) = "xlsx"
then
Qexcel = Qexcel + 1
elseif right(objfile.name, 3) = "mdb" or right(objfile.name, 5) = "accdb"
then
Qaccess = Qaccess + 1
end if
next

set objfiles = nothing
Countfiles objfolder
end if
next
end sub
**********************************************************



"Pegasus (MVP)" <I.can@fly.com.oz> ¼¶¼g©ó¶l¥ó·s»D:ud6rit31IHA.5664@TK2MSFTNGP02.phx.gbl...
>
> "Tony WONG" <x34@netvigator.com> wrote in message
> news:e%23J9s121IHA.2068@TK2MSFTNGP05.phx.gbl...
>>i have a vbs to count number of doc files, like this
>> for each folder in folders .... next
>>
>> the script is completely ok to count files in the folders with file
>> rights permission.
>>
>> however, i try to run it in other folders without file rights, like
>> c:\documents and settings\OtherUser.... it has a script error
>>
>> then i use "on error resume next" to try to bypass the folder
>>
>> the script can be finished. but the count calculation is completely
>> wrong. funny is that it return result of 1732 doc files but i don't have
>> permission to look into the folder.
>>
>> my question is how can i bypass the folder which i don't have file
>> permission.
>>
>> my script is supposed to loop through all the folders in a drive.
>>
>> Thanks a lot.
>>
>> tony
>
> Sorry, can't tell without seeing your script.
>



Re: Bypass folders without file permissions by Pegasus

Pegasus
Fri Jun 27 07:40:26 CDT 2008


"Tony WONG" <x34@netvigator.com> wrote in message
news:O7xg$l$1IHA.1768@TK2MSFTNGP03.phx.gbl...
> Hi Pegasus
>
> here is the code. there is problem when touch with unauthorized folders.
> ******************************************************
> dim Qword, Qexcel, Qaccess
> Set objFSOc = CreateObject("Scripting.FileSystemObject")
> set objdriveC = objFSOc.getfolder("C:\Documents and Settings")
>
> Qword = 0
> Qexcel = 0
> Qaccess = 0
>
> Countfiles(objdriveC)
> msgbox(Qword & " - " & Qexcel & " - " & Qaccess)
>
> sub Countfiles(objDrive)
> on error resume next
> for each objfolder in objDrive.subfolders
> if objfolder.name <> "Program Files" and objfolder.name <> "Default User"
> and objfolder.name <> "RECYCLER" and objfolder.name <> "All Users" and
> objfolder.name <> "Media Player" and objfolder.name <> "System Volume
> Information" and objfolder.name <> "NetworkService" and objfolder.name <>
> "MSOCache" and objfolder.name <> "LocalService" then
> set objfiles = objfolder.files
> for each objfile in objfiles
> if right(objfile.name, 3) = "doc" or right(objfile.name, 4) = "docx"
> then
> QWord = Qword + 1
> elseif right(objfile.name, 3) = "xls" or right(objfile.name, 4) = "xlsx"
> then
> Qexcel = Qexcel + 1
> elseif right(objfile.name, 3) = "mdb" or right(objfile.name, 5) =
> "accdb" then
> Qaccess = Qaccess + 1
> end if
> next
>
> set objfiles = nothing
> Countfiles objfolder
> end if
> next
> end sub
> **********************************************************

Your problem is not so much the way you process protected folders.
There are some conceptual problems in your script, which is why it
is absolutely essential to post the script when asking a question.

Here are the problems I see:
- There is a lack of clarity in what you're doing with your profile
folders. You process each profile folder in turn, then you drill
down into the subfolders. If a profile folder can't be accessed
then you still attempt to drill down into the subfolders. Why?
- I think that nested if / elsif / elsif statements are evil. They are
great for computers but they make the code very hard to read
for humans. In your case the logic cries out for a "Case" statement.
- The code that deals with folders that should be ignored is messy.
There are far too many "if xx <> yy and aa <> bb" etc. You could
do this with one single "instr" statement.

About the structure of your code: Some pseudo-code might help.

Main routine: It invokes Subroutine1 with the parent name of your
profiles folders.

Subroutine1: It calls Subroutine2 for useful profile folders and it skips
useless profile folders.

Subroutine 2: It processes the nominated profile folder recursively.

And here is the code that will do it:

Set objFSO = CreateObject("Scripting.FileSystemObject")
ProfileFolder = "C:\Documents and Settings"
IgnoredFolders = _
"#Program Files" & _
"#Default User" & _
"#RECYCLER" & _
"#All Users" & _
"#Media Player" & _
"#System Volume Information" & _
"#Network Service" & _
"#MSOCache" & _
"#LocalService#"

Qword = 0
Qexcel = 0
Qaccess = 0

ProcessProfiles(ProfileFolder)
MsgBox(Qword & " - " & Qexcel & " - " & Qaccess)

Sub ProcessProfiles(Profiles)
Set objfolders = objFSO.GetFolder(Profiles)
For Each objfolder In objfolders.subfolders
If InStr(IgnoredFolders, "#" & objfolder.name & "#") = 0 Then
CountFiles(objfolder.Path)
Next
End Sub

Sub CountFiles(path)
WScript.Echo "Processing " & path
Set objSubFolder = objFSO.GetFolder(path)
On Error Resume Next
For Each objfile In objSubFolder.files
if err.number > 0 then Exit Sub
Select Case LCase(Right(objfile.name, 4))
Case "docx" Qword = Qword + 1
Case ".xls" Qexcel = Qexcel + 1
Case "xlsx" Qexcel = Qexcel + 1
Case ".mcb" Qaccess = Qaccess + 1
End Select
Next
On Error Goto 0

For Each objfolders In objSubFolder.SubFolders
CountFiles objfolders.path
Next
End Sub



Re: Bypass folders without file permissions by Tony

Tony
Sat Jun 28 02:35:55 CDT 2008

Hi Pegasus

Thanks a lot for your deep clarification and your time.

it corrects me a lot.

tony


"Pegasus (MVP)" <I.can@fly.com.oz> ¼¶¼g©ó¶l¥ó·s»D:eOl77LF2IHA.4920@TK2MSFTNGP05.phx.gbl...
>
> "Tony WONG" <x34@netvigator.com> wrote in message
> news:O7xg$l$1IHA.1768@TK2MSFTNGP03.phx.gbl...
>> Hi Pegasus
>>
>> here is the code. there is problem when touch with unauthorized
>> folders.
>> ******************************************************
>> dim Qword, Qexcel, Qaccess
>> Set objFSOc = CreateObject("Scripting.FileSystemObject")
>> set objdriveC = objFSOc.getfolder("C:\Documents and Settings")
>>
>> Qword = 0
>> Qexcel = 0
>> Qaccess = 0
>>
>> Countfiles(objdriveC)
>> msgbox(Qword & " - " & Qexcel & " - " & Qaccess)
>>
>> sub Countfiles(objDrive)
>> on error resume next
>> for each objfolder in objDrive.subfolders
>> if objfolder.name <> "Program Files" and objfolder.name <> "Default User"
>> and objfolder.name <> "RECYCLER" and objfolder.name <> "All Users" and
>> objfolder.name <> "Media Player" and objfolder.name <> "System Volume
>> Information" and objfolder.name <> "NetworkService" and objfolder.name <>
>> "MSOCache" and objfolder.name <> "LocalService" then
>> set objfiles = objfolder.files
>> for each objfile in objfiles
>> if right(objfile.name, 3) = "doc" or right(objfile.name, 4) =
>> "docx" then
>> QWord = Qword + 1
>> elseif right(objfile.name, 3) = "xls" or right(objfile.name, 4) =
>> "xlsx" then
>> Qexcel = Qexcel + 1
>> elseif right(objfile.name, 3) = "mdb" or right(objfile.name, 5) =
>> "accdb" then
>> Qaccess = Qaccess + 1
>> end if
>> next
>>
>> set objfiles = nothing
>> Countfiles objfolder
>> end if
>> next
>> end sub
>> **********************************************************
>
> Your problem is not so much the way you process protected folders.
> There are some conceptual problems in your script, which is why it
> is absolutely essential to post the script when asking a question.
>
> Here are the problems I see:
> - There is a lack of clarity in what you're doing with your profile
> folders. You process each profile folder in turn, then you drill
> down into the subfolders. If a profile folder can't be accessed
> then you still attempt to drill down into the subfolders. Why?
> - I think that nested if / elsif / elsif statements are evil. They are
> great for computers but they make the code very hard to read
> for humans. In your case the logic cries out for a "Case" statement.
> - The code that deals with folders that should be ignored is messy.
> There are far too many "if xx <> yy and aa <> bb" etc. You could
> do this with one single "instr" statement.
>
> About the structure of your code: Some pseudo-code might help.
>
> Main routine: It invokes Subroutine1 with the parent name of your
> profiles folders.
>
> Subroutine1: It calls Subroutine2 for useful profile folders and it skips
> useless profile folders.
>
> Subroutine 2: It processes the nominated profile folder recursively.
>
> And here is the code that will do it:
>
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> ProfileFolder = "C:\Documents and Settings"
> IgnoredFolders = _
> "#Program Files" & _
> "#Default User" & _
> "#RECYCLER" & _
> "#All Users" & _
> "#Media Player" & _
> "#System Volume Information" & _
> "#Network Service" & _
> "#MSOCache" & _
> "#LocalService#"
>
> Qword = 0
> Qexcel = 0
> Qaccess = 0
>
> ProcessProfiles(ProfileFolder)
> MsgBox(Qword & " - " & Qexcel & " - " & Qaccess)
>
> Sub ProcessProfiles(Profiles)
> Set objfolders = objFSO.GetFolder(Profiles)
> For Each objfolder In objfolders.subfolders
> If InStr(IgnoredFolders, "#" & objfolder.name & "#") = 0 Then
> CountFiles(objfolder.Path)
> Next
> End Sub
>
> Sub CountFiles(path)
> WScript.Echo "Processing " & path
> Set objSubFolder = objFSO.GetFolder(path)
> On Error Resume Next
> For Each objfile In objSubFolder.files
> if err.number > 0 then Exit Sub
> Select Case LCase(Right(objfile.name, 4))
> Case "docx" Qword = Qword + 1
> Case ".xls" Qexcel = Qexcel + 1
> Case "xlsx" Qexcel = Qexcel + 1
> Case ".mcb" Qaccess = Qaccess + 1
> End Select
> Next
> On Error Goto 0
>
> For Each objfolders In objSubFolder.SubFolders
> CountFiles objfolders.path
> Next
> End Sub
>
>