https://community.documentfoundation.org/t/local-distant-file-exists/12562

Hello,

I use Libre Office calc (for the moment) for managing some 20 000+ URL files local links.
These files are located :

  • On my local hard drive (only on windows : c:\users\me\file1.pdf)
  • on my national intranet network (http://www.myLocalDomain.local/temp/file2.pdf )
  • on my local network (\MyServer\my file.pdf). Some files are linked on a network hard drive with a letter : o:\MyFile.pdf)

I use Libre Office calc for managing all these files (links, dates of updates, author…) because Calc is very usefull for simulating a database (we don’t have access to a database because of rights management s!)

How to test with a cURL function the presence (or absence) of the remote file?
Is the FileExists function can test the remote file on another server than which the OOCalc file is stored ?

Thanks a lot

for http://... rather WEBSERVICE

WEBSERVICE() though loads the entire content behind the URL, which probably is unwanted overkill.
Rather write a short macro that iterates over cells and for each executes a system call using the Shell Function with curl -I ... or a shell script using it and redirects/appends output or status information, that then can be loaded into Calc.

2 Likes

fancy to add a second [optional] parameter ? (then a third for POST ? :wink: )

at naive glance, seems reachable … interpr7.cxx (revision c8f7408d) - OpenGrok cross reference for /core/sc/source/core/tool/interpr7.cxx

Adding parameters to interoperable (e.g. with Excel) functions is always a bad idea.

then WEBSERVICE.HEAD() ?

1 Like

That’s a solution, but I must test if I have right to do that. Th’ast’s why I ask my question for using an “internal” LO solution. I am not sure I have right fos launching Shell function…

However, I will test WEBSERVICE.HEAD ( I haven’t see that) because I think it is the better way In my context of “not admin of my work PC”

I will test tomorrow

Thanks to all

no need. It doesn’t exist (yet!)
that was just a lobby-istic question to @erAck (who is THE specialist of Calc);

with a bit of positive feedback, we might make it an enhancement request,
then get a bit of traction to an easyHack,
etc etc …

meanwhile the macro approach he suggested would be the way for voluminous docs.

I have test at home the solution, all is OK (very long but OK)
However, I have tested yesterday in reals contions at work, on my LAN and all is … catastrophic !
It is not a LO probleme, but our LAN problem with all the specifics rights (a network with sensitives datas therefore super very protected)
I have kept yours solutions and I will test on excel if the solutions are faster (I am not a great fan but using Excel ils very recommended at work !)
Thanks a lot

Hi, you may also want to try the below function. Maybe it is faster than the WEBSERVICE
Good luck,
ms777

Global oUCB as Any

Sub Main
	msgbox pathExists("https://www.ffmpeg.org/ffmpeg-all.html")
end sub

function pathExists(aUrl as String)

	if IsEmpty(oUCB) then 
		oUCB = createUnoService("com.sun.star.ucb.UniversalContentBroker")
		oUCB.Initialize(Array("Local", "Office"))
	endif

	xId = oUCB.createContentIdentifier(aUrl)
	xContent = oUCB.queryContent(xId)

	Dim aProps(0) as new com.sun.star.beans.Property
	aProps(0).Name = "IsDocument"

	Dim aCommandGetPropertyValues as new com.sun.star.ucb.Command
	aCommandGetPropertyValues.Name = "getPropertyValues"
	aCommandGetPropertyValues.Argument = aProps

	xValues = xContent.execute(aCommandGetPropertyValues, 0, null)

	iCol = xValues.findColumn("IsDocument")
	pathExists = xValues.getBoolean(iCol)
End function

If someone want to have the solutioin I have done (in french with auto-translate) : Comment me suis-je sorti de mon souci de test de la présence (ou pas) de fichiers sur mon "serveur" (html statique) Web ?