CELL("filename") and #s

Hi, in Calc, I am using =CELL(“filename”) to display the filename in a cell. If the filename has a # character, eg. /home/guest/Untitled #1.ods, the resulting string will be ‘file:///home/guest/Untitled %231.ods’#$Sheet1. The # is URL encoded(?) as %23. Is it possible to have it return the actual filename (with the # in it)?

Thanks!

Unsolicited:
File or folder names containing special characters and/or spaces are a plague.

Thanks. MYDECODEURL() works as a general function for decoding URI encoded strings, ie. a counterpart of ENCODEURL(). Works for my case. :grinning:

Yes that’s URI-encoded name.

There’s no built-in counterpart for ENCODEURL spreadsheet function. You can create your own user-defined function using a macro like

Function MYDECODEURL(s)
  MYDECODEURL = ConvertFromURL(s)
End Function

Your function works in the Basic IDE only. When used as a cell function, it returns the original URL, even if you remove the single quotes.

REM  *****  BASIC  *****

Sub Main
msgbox MYDECODEURL(ThisComponent.getURL())
End Sub

Function MYDECODEURL(s)
mid s, 1, "'",""
  MYDECODEURL = ConvertFromURL(s)
End Function

What was this for? mid takes length, where you pass quotes…
But the correct use would be to extract everything inside the single quotes - the fragment (the # plus the rest) also breaks the conversion.

The mid statement removes the quotes enclosing the protocol, path and file name.
Please, forget my quick shot. It is wrong by any means.
This one seems to work, because it decodes the part between the two quotes.

Function MYDECODEURL(s)
s2 = mid(s,2,instr(2,s,"'")-2)
  MYDECODEURL = ConvertFromURL(s2)
End Function

I’d rather prefer

Function MySystemPathName()
MySystemPathName = ConvertFromURL(ThisComponent.getURL())
End Function
2 Likes

MySystemPathName() works too. A direct replacement for CELL(“filename”). Thanks :grinning: