Recognize a network-url

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
Nobackup
Posts: 1
Joined: Mon Feb 04, 2013 11:43 pm

Recognize a network-url

Post by Nobackup »

Hi!

I write a macro that must do something with a document if the document is stored on a networkdrive on windows.
My network drive \\server\mm\ is mapped to D:\ . The Document-URL is always file:///D:/myfile.ods.
How can I find out the real network path.
(In Excel with VB I can test with WNetGetConnection(...) for a vality network path.)

Thanks very much
OpenOffice 3.x on Windows 7 / SuSE Linux 12.x
rudolfo
Volunteer
Posts: 1488
Joined: Wed Mar 19, 2008 11:34 am
Location: Germany

Re: Recognize a network-url

Post by rudolfo »

Network mapped drives on MS Windows means that the servername and the name of the SMB share are mapped to a drive letter. This means if you have a UNC path \\server\mm\ that is mapped to drive D:\ everything that comes behind this will be the same:
\\server\mm\a-very\deep\directory\path\with\a-file.txt
will become
D:\a-very\deep\directory\path\with\a-file.txt

If you know that \\server\mm is the UNC path for the network mapped drive your problem is solved. It is simply a question of string substitution.

But it seems like you are rather asking how you can find out wether a drive E: is a local drive or a network drive. Your only chance is to ask the OS: Try the gold old net use. If you are using Basic as a programming language you will have a pretty hard time to capture its output and parse it for the string E:.
Python makes this a lot easier with the open() and popen() commands.

Code: Select all

C:> net use

Status       Lokal     Remote                    Netzwerk
-------------------------------------------------------------------------------
OK           E:        \\iova\shared             Microsoft Windows Network
OpenOffice 3.1.1 (2.4.3 until October 2009) and LibreOffice 3.3.2 on Windows 2000, AOO 3.4.1 on Windows 7
There are several macro languages in OOo, but none of them is called Visual Basic or VB(A)! Please call it OOo Basic, Star Basic or simply Basic.
User avatar
karolus
Volunteer
Posts: 1228
Joined: Sat Jul 02, 2011 9:47 am

Re: Recognize a network-url

Post by karolus »

Hallo
Additional to Rudolfo:
Do explizit test with:
>: net use D:

Karolus
AOO4, Libreoffice 6.1 on Rasbian OS (on ARM)
Libreoffice 7.4 on Debian 12 (Bookworm) (on RaspberryPI4)
Libreoffice 24.8… flatpak on Debian 12 (Bookworm) (on RaspberryPI4)
Post Reply