FSO object and spaces in file names

Good Morning all!!

I am using the FSO object to read in files that are included in a folder and then turning around and spitting them out as hyper links.

Once the user clicks on the links I am passing the file name in the query string as I reload the page for the next step in processing.

Here is the problem.  If I have spaces in the file name (as most of our docs do) then when I read in the file the name is being truncated at the first space.  I have searched the web and EE for a resolution and other then re-writing my code to use the GetFile method rather then the GetFolder method I am not sure how to read in the files in the folder that have spaces in them.

Here is a snippet of my code:

Set fso = CreateObject("Scripting.FileSystemObject")
Set folder = fso.GetFolder(fileloc)
Set files = folder.Files
For Each file in files
                  redim preserve dir2(i)
                  dir2(i)= file.name
                  redim preserve dir3(i)
                  dir3(i)= file.datelastmodified
                  redim preserve dir4(i)
                  dir4(i)= file.size
                     i = i + 1

As an aside... I know I could use a multi dimensional array rather then 3 different ones but I added them in at different times and this was easier :-/
Who is Participating?
peh803Connect With a Mentor Commented:
try executing server.urlencode() around the querystring value before you pass it into the querystring...this should help...


If you are passing the filename in the querystring you could try replacing the spaces with %20

so in your code instead of

dir2(i)= file.name


dir2(i)= replace(file.name," ","%20")

Then when you read the file name from the querystring you could pass it back through to change the %20 back in to a space. so something like

filename = replace(request.querystring("filename"),"%20"," ")

Another way to do this without the querystring might be to store the file name in a hidden tag on the form. Then when you submit the form you could use Request.Form("[filename field]")


lharrispvAuthor Commented:
Thanx for the response!!

The problem is that by the time the name gets into the query string it is already truncated.  This is happening when I first read the file name in with FSO object.

so in your for loop if you add a response.write

                redim preserve dir2(i)
               dir2(i)= file.name
               response.write file.name

then the output file.name is already truncated at the first space there?

What do you get when you do this--are the names truncated here:

for i=0 to UBound(dir2)
   Response.write(dir2(i) & "<BR>")

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.