[SOLVED] How do I test for an external file?

Keyboard macros or custom scripts

[SOLVED] How do I test for an external file?

Postby CarlB » Tue Jul 09, 2019 8:38 pm

I would like to test for the existing of an external file from within a cell formulae e.g.

if c:\users\carl\tst.txt exists then output "Yes" otherwise output ""

Is this possible in OO Calc?

Any help much appreciated
Last edited by MrProgrammer on Thu Aug 01, 2019 8:30 pm, edited 3 times in total.
Reason: Moved from Calc forum to OpenOffice Basic, Python, BeanShell, JavaScript
OpenOffice 4.1.6 on Windows 10 64-bit
CarlB
 
Posts: 2
Joined: Tue Jul 09, 2019 8:34 pm

Re: How do I test for an external file?

Postby RusselB » Wed Jul 10, 2019 1:05 am

Welcome to the Forums.
Based on the wording of your request, while Calc might be able to do this, I believe it would require a macro.
I'm not familiar with macros, but a quick Google search brought up https://stackabuse.com/python-check-if-a-file-or-directory-exists/
As this is a Python code, it (to my knowledge) is compatible with Calc, and thus may be what you are wanting.
OpenOffice 4.1.7 and LibreOffice 6.3.3.2 on Windows 7 Pro & Ultimate
If you believe your problem has been resolved, please go to your first post in this topic, click the Edit button and add [Solved] to the beginning of the Subject line.
User avatar
RusselB
Moderator
 
Posts: 5677
Joined: Fri Jan 03, 2014 7:31 am
Location: Sarnia, ON

Re: How do I test for an external file?

Postby Zizi64 » Wed Jul 10, 2019 6:12 am

You can test it with a macro written in the Basic. The Basic has IDE in the AOO/LO. The usage of the Basic maybe easier than the Python for a beginner.

Code: Select all   Expand viewCollapse view
REM  *****  BASIC  *****
Option explicit

Function MyFileExists(sFullPath as string) as boolean

dim sFileUrl as string

   sFileURL = ConvertToUrl(sFullPath)   
   
   If FileExists(sFileUrl) then
      MyFileExists = True
   else
      MyFileExists = False
   end if
End function


Copy the code into a Module of the MyMacros, and then you will able to call the function from a cell of any spreadsheet document.
Tibor Kovacs, Hungary; LO6.1.6 on Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-6.3.3; AOO4.1.6
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
 
Posts: 8537
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: How do I test for an external file?

Postby CarlB » Wed Jul 10, 2019 11:15 am

That's great thanks
OpenOffice 4.1.6 on Windows 10 64-bit
CarlB
 
Posts: 2
Joined: Tue Jul 09, 2019 8:34 pm


Return to OpenOffice Basic, Python, BeanShell, JavaScript

Who is online

Users browsing this forum: No registered users and 3 guests