Replace on FSO

Results 1 to 2 of 2

Thread: Replace on FSO

  1. #1
    Join Date
    Dec 1969

    Default Replace on FSO

    I trying to remove the extension and I am doing a Replace on a FSO and I am getting an error:<BR><BR>Cannot use parentheses when calling a Sub <BR><BR>/shineReportView.asp, line 14 <BR><BR>replace(apples, "pdf", "")<BR>--------------------------^<BR><BR>I create a var apples and have it set to<BR><BR>My code is this:<BR><BR>filepath = server.mappath("pdf/do_not_delete.txt")<BR>Set file = server.createobject("Scripting.FileSystemObject")< BR>set fileItem = file.GetFile(filePath)<BR>SET parent = fileItem.ParentFolder<BR>Set parentFolderFiles = parent.Files<BR><BR>for each fileitem in parentFolderFiles<BR> apples =<BR> replace(apples, "pdf", "")<BR> response.write("&#060;li&#062;&#060;a target=&#039;_blank&#039; href=&#039;pdf/" & & "&#039;&#062;" & apples & "&#060;/a&#062;&#060;/li&#062;")<BR>next<BR><BR>Thanks,<BR><BR>Chris

  2. #2
    Join Date
    Dec 1969

    Default Replace() is a function and not a sub...

    ...and it returns the string after everything has been replaced. Normally you reassign it back to the original variable:<BR><BR>apples = Replace(apples, "pdf", "")<BR><BR>By the way, what if the filename contains pdf, e.g. This_is_my_pdf.pdf? Do you want to replace that also? Or just extensions? If you want to do just extensions, I suggest your extract the extension first, then replace it if nessary and then reappend it:<BR><BR>ext = Mid(apples, InstrRev(apples, "."))<BR>apples = Left(apples, Len(apples) - Len(ext))<BR>ext = Replace(ext, ".pdf", "")<BR>apples = apples & ext<BR><BR>Oliver.<BR><BR>Oliver.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts