The Forum has been Updated
The code has been upgraded to the latest .NET core version. Please check instructions in the Community Announcements about migrating your account.
I want to check for the existence of files using FSO, but if the file path and/or name include an apostrophe, the program breaks. Anyone have a suggestion?
Example code:
Example code:
Code:
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
If not objFSO.FileExists(strPath&strFile) Then
strErr=strErr & "<li>"&strFile&" does not exist.</li>"
Else
objFSO.Close
End If
Set objFSO = Nothing
نوشته شده در
try escaping any apostrophes with a slash, so try a replace on strFile to replace ' with \'
نوشته شده در
Replacing with an \' or with an '' doesn't work. Any other suggestions?
نوشته شده در
well, from what I can find out, the FSO should not have any problem with filenames containing an apostrophe, are you sure that is definitely what is causing the problem ?
نوشته شده در
From the Script Guy's Blog Incidentally, if you’re using the FileSystemObject (another way to work with files and folders), you don’t have to worry about this; the apostrophe doesn’t seem to bother the FileSystemObject. For example, if you want to know the size of Ken Myer’s Folder, use this code:
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("C:\Ken Myer’s Folder")
Wscript.Echo "Size: " & objFolder.Size
No escaping or other coding tricks required.
نوشته شده در
The code works perfectly on all folders/files except for those containing an apostrophe and/or an ampersand.
نوشته شده در
what are you actually getting when you run your code, I just tried this myself and it works quite happily with ampersand and apostrophes in file names
نوشته شده در
this is the code I ran, and it quite happily displays that the file exists
results in
Code:
<%
strPath = "c:\temp\"
strFile = "apostroph'e&ersand.txt"
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
If not objFSO.FileExists(strPath&strFile) Then
strErr=strErr & "<li>"&strFile&" does not exist.</li>"
Else
strErr=strErr & "<li>"&strFile&" exists.</li>"
End If
Set objFSO = Nothing
Response.Write strErr
%>- apostroph'e&ersand.txt exists.
نوشته شده در
Found it - wasn't in this routine but in the chkstring function; was resulting in a double apostrophe before checking the file name. Thanks. Now if only I could figure out that javascript mouse-over routine, I'd be through with this and I could rest.
آخرین ویرایش توسط
نوشته شده در
This is very old, but here's an update. I solved the mouseover Javascript routine by replacing apostrophes with the U+2032 symbol (#8242;). They still look like apostrophes (and actually sort properly now whereas the apostrophe didn't), so now the Javascript is happy.
Email Member
Message Member
Post Moderation
بارگزاری فایل
If you're having problems uploading, try choosing a smaller image.
پیشنمایش مطلب
Send Topic
Loading...