FileSystemObject problem

avir
avir used Ask the Experts™
on
Hello
I'm wondering if anyone is willing to look into a problem that I have already resolved, but not in the way I had originally intended. So I am really interested in knowing why my original solution did not work.
I have thumbnails, large images and hi-res images located in a series of folders and subfolders.
I have the paths to the thumbnails and partial paths to the large images listed in 2 sql tables, one in English and one in Hebrew.
I've taken a list of items from queries in English and Hebrew, manipulated the URL strings of the image paths in order to find the last "/" in the path and with that, found a function using the ASP FO object that will allow me to find which folders contain subfolders with the hi-resolution images and then link to them.
This works fine with the English query, but not with the Hebrew, even though it's the same URL path. For some reason, somewhere along the way,  the last "/" gets moved to the beginning of the string and I get a "path not found" error for this line:
set fo=fs.GetFolder(path)
This is an example of a path, when I do a response.write:
\E:\site\images\Corridor\Judaica\ethnography\Permanent Exhibition 2010
Would anyone be interested in looking into this for me?
Thanks,

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
Hi,

I don't know the solution for VB, but I believe GetFolder doesn't support Unicode, or in your case Codepages correctly.

You need to find the right function that supports Code pages, or Unicode.

Sorry I can't help more.
Most Valuable Expert 2012
Top Expert 2014

Commented:
Hi, I'm not sure how to approach the original issue, because I don't know how you're *getting* the path string, but you could strip off the first slash, and append one to the end, to make sure.

If Left(path, 1) = "\" Then path = Mid(path, 2)
If Right(path, 1) <> "\" Then path = path & "\"
set fo=fs.GetFolder(path)

Regards,

Rob.

Commented:
Have you ensured you pages are fully UTF-8:

At the very top of every page:
<%@ Language=VBscript Codepage="65001" %>
In the head:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
and saved in notepad (as an example bit of software) as "UTF-8".

If the slash is consistent in it's placement then I like Robs idea above.

Good luck

/ Tobzzz
Should you be charging more for IT Services?

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
Thanks Rob. I tried that, but with the same result. It's almost as if the last "/" is at the end, but the object thinks it's at the beginning or something like that. Maybe there is something else I'm doing wrong.
I've attached the relevant part of the code I am using with your suggestion and here is the result:

imagePath: E:\site\images\Corridor\Judaica\subjects\Feuchtwanger\HF0009.jpg
Pos: 54
E:\site\images\Corridor\Judaica\subjects\Feuchtwanger\
E:\site\images\Corridor\Judaica\subjects\Feuchtwanger

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
sub GetHiRez()
'----------link to the hi-resoluton image------------

dim imagePath : imagePath = "E:\site\images\Corridor\" & rs.fields("MultimediaE") 'physical path + the particular item's path from the sql table
	response.Write "imagePath: "&imagePath & "<br>"
Dim pos : pos = (InStrRev(imagePath,"\")) 'Locate the last \ in the path
	response.write "Pos: " & pos& "<br>"
dim path: path = Left(imagePath,pos) ' the path up until the last \
	response.write path & "<br>"
If Left(path, 1) = "\" Then path = Mid(path, 2) ' try and remove the \ from the beginning of the path
If Right(path, 1) <> "\" Then path = path & "\"
	response.write  path & "<br>"  ' new path
	response.end	
'---------replace /thumb folder with hi-resolution folder----------
dim bigPath : bigPath = replace(rs("MultimediaTypeE"), "/thumb", "/hi_rez")
dim fs,fo,x
set fs=Server.CreateObject("Scripting.FileSystemObject")
set fo=fs.GetFolder(path)
'check the list of subfolders in the image path
for each x in fo.SubFolders
'----check to see if there is a hi_rez subfolder in the images directory
if x.Name = "hi_rez" then 'replace thumb folder with hi_rez folder in the link path
%>
<a href='hi-resolution.asp?path=<% =bigPath%>'><img src='images/enlarge.png' alt='Enlarge' width='34' height='34' style=' vertical-align:middle' /></a>
<%
else
end if
next
set fo=nothing
set fs=nothing
end sub 
%>

Open in new window

Author

Commented:
I just noticed that when I pasted the results from the web page and also looking at the web page source I see that the last "/" gets placed back at the end, even though it isn't displayed that way on the page.

Commented:
That is because of proper handling by the browser

it knows it's a different code page and requires handling with right to left

Author

Commented:
I'm sorry, I got confused. That's what happens after working on too many things at once. Anyways, your suggestion did work for many of the items, but I'm still getting an error for some. I think I'll have to take a closer look at the paths that aren't working and see how they are different.
Most Valuable Expert 2012
Top Expert 2014

Commented:
Hi, your output seems slightly odd.  You have this:
E:\site\images\Corridor\Judaica\subjects\Feuchtwanger\

which is determined by this:
path = Left(imagePath,pos) ' the path up until the last \
response.write path & "<br>"

but then this is shown:
E:\site\images\Corridor\Judaica\subjects\Feuchtwanger

from this:
If Left(path, 1) = "\" Then path = Mid(path, 2) ' try and remove the \ from the beginning of the path
If Right(path, 1) <> "\" Then path = path & "\"
response.write  path & "<br>"  ' new path

which seems really strange.  I can't see when the last slash is actually removed from the Left and Right character checks....

Does it make any difference if you change this:
imagePath = "E:\site\images\Corridor\" & rs.fields("MultimediaE")

to this:
imagePath = "E:\site\images\Corridor\" & CStr(rs.fields("MultimediaE"))

Regards,

Rob.

Author

Commented:
I'll try this when I get back to the office tomorrow.

Author

Commented:
Hi Rob
I've been playing around with this for quite some time now and I see what gets returned with or without your additional code is this kind of path:
E:\site\images\Corridor\Judaica\subjects\Feuchtwanger\
and the "\" at the beginning was just being displayed as such, but it's really at the end.
And then sometimes it works and the image is displayed and sometimes it doesn't and I get the "path not found" error. And for the life of me, I cannot figure out why it works for some images and not for others. I do see also that in the instances when I substitute the actual complete URL instead of the call to the rs then it works fine.
Most Valuable Expert 2012
Top Expert 2014

Commented:
Perhaps it's a timing issue.  You could trying check if the file exists:
If fso.FileExists(path) = False Then path = ""

But what is the actual line the error is occurring at?  We should do some error trapping around that line maybe?

Rob.

Author

Commented:
Hi Rob
I tried this and it did sidetrack the error I was receiving previously, but the procedure still isn't working and it doesn't recognize the path. I think it must be related to the "where" clause in the original query which is in Hebrew.
You can see at this link what happens when you click on one of the thumbnails. Although I'm not sure this link will work for you since it has Hebrew in the URL parameter.
http://www.imj.org.il/judaica_visitor_center/Galleries/he/showRoomTest.asp?RoomID=22&Gallery=¿¿¿¿ ¿¿¿ ¿¿¿¿¿¿ ¿¿¿¿¿¿
<%
sub GetHiRez()
'--------------------------------link to the hi-resoluton image-------------------------------

dim imagePath : imagePath = "E:\site\images\Corridor\" & Cstr(rs.fields("MultimediaE")) 'physical path + the particular item's path from the sql table

Dim pos : pos = (InStrRev(imagePath,"\")) 'Locate the last \ in the path

dim path: path = Left(imagePath,pos) ' the path up until the last \

dim bigPath : bigPath = replace(rs("MultimediaTypeE"), "/thumb", "/hi_rez")
dim fs,fo,x
set fs=Server.CreateObject("Scripting.FileSystemObject")
If fs.FileExists(path) = False Then 
path = ""
response.write "this Path is is not working: " & bigPath & "<br>"
else
set fo=fs.GetFolder(path)
'check the list of subfolders in the image path
for each x in fo.SubFolders
'check to see if there is a hi_rez subfolder in the images directory
if x.Name = "hi_rez" then 'replace thumb folder with hi_rez folder in the link path
%>
<a href='hi-resolution.asp?path=<% =bigPath%>'><img src='images/enlarge.png' alt='Enlarge' width='34' height='34' style=' vertical-align:middle' /></a>
<%
else
end if
next
end if
set fo=nothing
set fs=nothing
end sub 
%>

Open in new window

Author

Commented:
Of course the link doesn't work. Here's a screenshot.
showroomItem.jpg
Most Valuable Expert 2012
Top Expert 2014
Commented:
Hi, in the code snippet you posted, I can't see the part that generates the URL with this path
showRoomTest.asp?RoomID=22&Gallery=¿¿¿¿ ¿¿¿ ¿¿¿¿¿¿ ¿¿¿¿¿¿

Is the Gallery parameter that you are generating with the path variable in your code snippet?

Also, I note that above your output "this Path is is not working", you have this:
If fs.FileExists(path) = False Then

But, seeing as path is currently a folder, you need to use
If fs.FolderExists(path) = False Then

which uses FolderExists instead of FileExists.

Regards,

Rob.

Author

Commented:
It works. Thank you very much.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial