FSO Question

Snitz™ Forums 2000
https://forum.snitz.com/forumTopic/Posts/69799?pagenum=1
05 November 2025, 09:33

Topic


Carefree
FSO Question
18 January 2011, 06:06


Here's an excerpt from a script:

Code:
					For Each objItem In colFiles
If InStr(1, objItem.Name, strQuery, vbTextCompare) <> 0 Then
%>
<tr bgcolor="#CCFFCC">
<td width="70%" align="left" ><a href="<% = strPath %><%= mid(objFolder,4) %>/<%= objSubFolder.Name %>/<%= objItem.Name %>"><%= objItem.Name %></a></td>
<td width="10%" align="right"><%= objItem.Size %></td>
<td width="20%" align="right" ><%= cstr(objItem.DateCreated) %></td>
</tr>
<%
End If
Next
I get occasional permission denied runtime errors (800a0046) for the first line in this routine. The folders in question all have permissions granted and there aren't any restricted system folders involved. How can I determine the objItem.Name in question when it fails?

 

Replies ...


kyodai
17 February 2011, 16:10


Without trying myself I'd instantly think of Response.Write" Item name " & objItem.Name

Otherwise i can only think of Try/Catch to debug this. Maybe the sever log will reveal more...
Carefree
18 February 2011, 06:13


The response.write method won't work here. If it doesn't read the file, it doesn't get a name.
AnonJr
18 February 2011, 08:41


Yeah, but if you have a running list of the names before it, you know what files it isn't. That can help in narrowing down the problem.
Carefree
18 February 2011, 22:53


I've tried that. Tried setting all permissions on the next "logical" file to be hit, same results. The program works from root-through on every drive that isn't a system drive, provided that there are no pagefiles or recycle bins.

BTW to eliminate automatically created recycle bins in non-system drives, first delete the recycle bin, then create a 0-byte text file, name it "Recycler", and finally set its attributes to system file, read-only, hidden. That'll prevent windows from recreating an unwanted/unused trash can.
Of course, if you do that - files you delete are just gone ... not in a trash can to be recovered or emptied.
Doug G
19 February 2011, 00:40


I don't know if this is useful, and it's a VB example not vbscript. It's an example of directory recursion using the filesystem object.
http://support.microsoft.com/kb/185601
Carefree
19 February 2011, 03:17


I've got it pulling files, directories, sub-directories; that's not an issue. The problem is in some hidden, unspecified files which do not want to cooperate with the FSO.
HuwR
19 February 2011, 04:44


are you sure it is erroring on the first line and not elsewhere, you should be able to iterate through a directory without it erroring on hidden/special files, since you should be able to display it's properties/attributes hidden or not, it should only error if you try to open them.
for example
Code:

SET oFSO = WScript.CreateObject("Scripting.FileSystemObject")
SET oFolder = oFSO.GetFolder("C:\MyPath")
For Each oFile In oFolder.Files
If oFile.Attributes And 2 Then
WScript.Echo oFile.Path & " is Hidden"
End If
Next
should give you a list of hidden files.
Maybe you could show is more of your code.
Carefree
19 February 2011, 07:35


Modified to remove sensitive info:
Code:

<html>
<head>
<title>Path Finder</title>
</head>
<body>
<!--#INCLUDE Virtual="xxxxxxxxxx/inc_sha256.asp"-->
<%
Response.Buffer = False
Server.ScriptTimeout = 900
Const FOR_READING = 1
dim ng
strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=XXXXXXXXXXXX"
strDBType = "access"
set my_Conn = Server.CreateObject("ADODB.Connection")
my_Conn.Open strConnString
if Request.Form("Pass") <> "" and Request.Form("User") <> "" then
strSQL="SELECT EMP_ID, EMP_NAME, EMP_FIRSTNAME, EMP_LASTNAME, EMP_PASSWORD FROM EMPLOYEES WHERE EMP_NAME = '" & Request.Form("User") & "'"
set rsAuthenticate=my_Conn.Execute(strSQL)
if not rsAuthenticate.EOF then
strLegalUser=rsAuthenticate("EMP_NAME")
strLegalFirst=rsAuthenticate("EMP_FIRSTNAME")
strLegalLast=rsAuthenticate("EMP_LASTNAME")
strLegalPass=rsAuthenticate("EMP_PASSWORD")
intID=rsAuthenticate("EMP_ID")
rsAuthenticate.Close
end if
Set rsAuthenticate = Nothing
if (sha256(Request.Form("Pass")) <> strLegalPass) then
Response.Write "Access denied!" & vbNewLine & _
" <meta http-equiv=""Refresh"" content=""6; URL=Searcher.asp"">" & vbNewLine
Response.End
else
Response.Write "<table align=""center"" width=""950""><tr valign=""middle""><td align=""left"">Hi " & strLegalFirst & " " & strLegalLast & ", </center><br></td></tr></table>"
Dim strPath ' Path of directory to search
Dim objFSO ' FileSystemObject variable
Dim objFolder ' Folder variable
Dim objItem ' Variable used to loop through the contents of the folder
Dim strQuery ' Search string
for i = 67 to 91 ' Drives C - Z
if Request.Form("HDISK" & chr(i)) = "on" then
strPath = "HDISK" & chr(i) & "/"
if strQuery = "" then strQuery = Request.Form("query")
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(Server.MapPath(strPath))
%>
<table align="center" width="950" border="0" cellspacing="0" cellpadding="2">
<tr valign="middle">
<td align="left" width="70%"> Here are the contents of <strong>HDisk <%= chr(i) %></strong> that match your query:
</td>
<td width="10%"> </td>
<td width="20%"> </td>
</tr>
</table>
<table align="center" width="950" border="5" bordercolor="green" cellspacing="0" cellpadding="2">
<tr bgcolor="#006600">
<td width="70%"><font color="#FFFFFF"><strong>File Name:</strong></font></td>
<td width="10%"><font color="#FFFFFF"><strong>File Size:</strong></font></td>
<td width="20%"><font color="#FFFFFF"><strong>Date Created:</strong></font></td>
</tr>
<%
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(Server.MapPath(strPath))
Set colFiles = objFolder.Files
For Each objItem In colFiles
If InStr(1, objItem.Name, strQuery, vbTextCompare) <> 0 Then
%>
<tr bgcolor="#CCFFCC">
<td width="70%" align="left" ><a href="<% = strPath %>/<%= objItem.Name %>"><%= objItem.Name %></a></td>
<td width="10%" align="right"><%= objItem.Size %></td>
<td width="20%" align="right" ><%= cstr(objItem.DateCreated) %></td>
</tr>
<%
End If
Next
ShowSubFolders(objFolder)
End if
Next

Sub ShowSubFolders(objFolder)
Set colFolders = objFolder.SubFolders
For Each objSubFolder In colFolders
strTitle=""
if not (uCase(objSubFolder.Name) = "SYSTEM VOLUME INFORMATION" or uCase(objSubFolder.Name) = "RECYCLER" or uCase(objSubFolder.Name) = "DOCUMENTS AND SETTINGS" or uCase(objSubFolder.Name) = "MSOCACHE" or uCase(objSubFolder.Name) = "CONFIG.MSI") then
Set colFiles = objSubFolder.Files
If InStr(1, objSubFolder.Name, strQuery, vbTextCompare) <> 0 Then
strTitle=mid(objSubFolder,4)
strTitle=replace(strTitle,"\","/") & "/"
strLink = strPath & strTitle
%>
<tr bgcolor="#CCFFCC">
<td width="70%" align="left" ><a href="<%= strLink %>"><%= objSubFolder.Name %></a></td>
<td width="10%" align="right"> </td>
<td width="20%" align="right" > </td>
</tr>
<%
end if
if not (ObjFolder = "c:\" or objSubFolder.Name="Documents and Settings") then
strTitle=mid(objSubFolder,4)
strTitle=replace(strTitle,"\","/") & "/"
For Each objItem In colFiles
strDate = cStr(objItem.DateCreated)
if len(strDate) < 22 then
if mid(strDate,2,1) = "/" then strDate = "0" & strDate
if mid(strDate,4,1) = "/" then strDate = left(strDate,2) & "0" & mid(strDate,3)
if mid(strDate,13,1) = ":" then strDate = left(strDate,11) & "0" & mid(strDate,12)
end if
If InStr(1, objItem.Name, strQuery, vbTextCompare) <> 0 Then
strLink = strPath & strTitle & objItem.Name
%>
<tr bgcolor="#CCFFCC">
<td width="70%" align="left" ><a href="<% = strLink %>"><%= objItem.Name %></a></td>
<td width="10%" align="right"><%= objItem.Size %></td>
<td width="20%" align="right" ><%= strDate %></td>
</tr>
<%
End If
Next
end if
ShowSubFolders(objSubFolder)
end if
Next
End Sub
Set objItem = Nothing
Set objFolder = Nothing
Set objFSO = Nothing
Response.Write "</table>"
end if
else
Response.Write "<form action=""Searcher.asp"" method=""post"" id=""authenticate"">" & vbNewLine & _
" <table align=""center"" width=""50%"" style=""border-collapse: collapse"" border=""1"" cellpadding=""5"" cellspacing=""1"">" & vbNewLine & _
" <tr valign=""middle"">" & vbNewLine & _
" <td align=""center"" width=""50%"" bgcolor=""cyan"">" & vbNewLine & _
" <font face=""arial bold"" size=""4"" color=""black"">User Name" & vbNewLine & _
" </font>" & vbNewLine & _
" </td>" & vbNewLine & _
" <td align=""center"" width=""50%"" bgcolor=""cyan"">" & vbNewLine & _
" <font face=""arial bold"" size=""4"" color=""black"">Password" & vbNewLine & _
" </font>" & vbNewLine & _
" </td>" & vbNewLine & _
" </tr>" & vbNewLine & _
" <tr valign=""middle"">" & vbNewLine & _
" <td align=""center"" width=""50%"" bgcolor=""cyan"">" & vbNewLine & _
" <font face=""arial bold"" size=""2"" color=""black"">" & vbNewLine & _
" <input type=""text"" name=""User"" size=""20"" maxlength=""50"">" & vbNewLine & _
" </font>" & vbNewLine & _
" </td>" & vbNewLine & _
" <td align=""center"" width=""50%"" bgcolor=""cyan"">" & vbNewLine & _
" <font face=""arial bold"" size=""2"" color=""black"">" & vbNewLine & _
" <input type=""password"" name=""Pass"" size=""20"" maxlength=""50"">" & vbNewLine & _
" </font>" & vbNewLine & _
" </td>" & vbNewLine & _
" </tr>" & vbNewLine & _
" <tr valign=""middle"">" & vbNewLine & _
" <td align=""center"" colspan=""2"" bgcolor=""cyan"">" & vbNewLine & _
" <font face=""arial"" size=""2"" color=""navy"">Find files whose names contain:" & vbNewLine & _
" </font>" & vbNewLine & _
" </td>" & vbNewLine & _
" </tr>" & vbNewLine & _
" <tr valign=""middle"">" & vbNewLine & _
" <td align=""center"" colspan=""2"" bgcolor=""cyan"">" & vbNewLine & _
" <input type=""text"" width=""50"" maxlength=""100"" name=""query"" value=""" & strQuery & """>" & vbNewLine & _
" </td>" & vbNewLine & _
" </tr>" & vbNewLine & _
" <tr valign=""middle"">" & vbNewLine & _
" <td align=""center"" colspan=""2"" bgcolor=""cyan"">" & vbNewLine & _
" <font face=""arial"" size=""2"" color=""navy""><b>Drives to Include:</b>" & vbNewLine & _
" </font>" & vbNewLine & _
" </td>" & vbNewLine & _
" </tr>" & vbNewLine & _
" <tr valign=""middle"">" & vbNewLine & _
" <td align=""center"" colspan=""2"" bgcolor=""cyan"">" & vbNewLine & _
" <font face=""arial bold"" size=""2"" color=""black"">" & vbNewLine & _
" <input type=""checkbox"" name=""HDISKC"">C" & vbNewLine & _
" <input type=""checkbox"" name=""HDISKD"">D" & vbNewLine & _
" <input type=""checkbox"" name=""HDISKE"">E" & vbNewLine & _
" <input type=""checkbox"" name=""HDISKF"">F" & vbNewLine & _
" <input type=""checkbox"" name=""HDISKG"">G" & vbNewLine & _
" <input type=""checkbox"" name=""HDISKH"">H" & vbNewLine & _
" <input type=""checkbox"" name=""HDISKI"">I" & vbNewLine & _
" <input type=""checkbox"" name=""HDISKJ"">J" & vbNewLine & _
" <input type=""checkbox"" name=""HDISKC"">K" & vbNewLine & _
" <input type=""checkbox"" name=""HDISKD"">L" & vbNewLine & _
" <input type=""checkbox"" name=""HDISKE"">M" & vbNewLine & _
" <input type=""checkbox"" name=""HDISKF"">N" & vbNewLine & _
" <input type=""checkbox"" name=""HDISKG"">O" & vbNewLine & _
" <input type=""checkbox"" name=""HDISKH"">P" & vbNewLine & _
" <input type=""checkbox"" name=""HDISKI"">Q" & vbNewLine & _
" <input type=""checkbox"" name=""HDISKJ"">R" & vbNewLine & _
" <input type=""checkbox"" name=""HDISKC"">S" & vbNewLine & _
" <input type=""checkbox"" name=""HDISKD"">T" & vbNewLine & _
" <input type=""checkbox"" name=""HDISKE"">U" & vbNewLine & _
" <input type=""checkbox"" name=""HDISKF"">V" & vbNewLine & _
" <input type=""checkbox"" name=""HDISKG"">W" & vbNewLine & _
" <input type=""checkbox"" name=""HDISKH"">X" & vbNewLine & _
" <input type=""checkbox"" name=""HDISKI"">Y" & vbNewLine & _
" <input type=""checkbox"" name=""HDISKJ"">Z" & vbNewLine & _
" </font>" & vbNewLine & _
" </td>" & vbNewLine & _
" </tr>" & vbNewLine & _
" <tr valign=""middle"">" & vbNewLine & _
" <td bgColor=""cyan"" colspan=""2"" align=""center""><input type=""submit"" value=""Submit"" id=""submit1"" name=""submit1"">" & vbNewLine & _
" </tr>" & vbNewLine & _
" </table>" & vbNewLine & _
"</form>" & vbNewLine
end if
%>
</body>
</html>
HuwR
19 February 2011, 08:20


I don't think this will matter, but worth checking.
1) you are setting objFSO twice, why? you don't need to do the second SET since you already have a valid objFSO
2) try not setting colfiles and do the iteration directly on onjFolder.Files it may make a difference, it could be that creating files object works differently in this instance.
Carefree
20 February 2011, 01:20


Didn't solve the issue, Huwr, but may have resulted in a slight speed improvement not using the collection.
HuwR
20 February 2011, 03:03


ok, I think the problem is that it is trying to iterate through a hidden directory rather than it being a file that is the problem, so you probably need to check the folder attributes before trying to iterate through it's files.
Maybe something like this
Code:

SET oFSO = WScript.CreateObject("Scripting.FileSystemObject")
SET oFolder = oFSO.GetFolder("C:\MyPath")
If oFolder.Attributes AND 2 then
//Folder is hidden so don't iterate the files
else If oFolder.Attributes AND 4
//System folder so don't iterate the files
else
For Each oFile In oFolder.Files
If oFile.Attributes And 2 Then
WScript.Echo oFile.Path & " is Hidden"
End If
Next
End If
© 2000-2021 Snitz™ Communications