You are viewing a plain text version of this content. The canonical link for it is here.
Posted to api@openoffice.apache.org by Johnny Rosenberg <gu...@gmail.com> on 2013/09/28 17:03:51 UTC

Basic macro – Retrieve folder of the current spreadsheet

Dim FolderPath As String, FilePath As String
FilePath=ConvertFromUrl(ThisComponent.getURL())

Now FilePath contains the URL of the file, let's say:
/home/guraknugen/SomeFolder/MySpreadsheet.ods

Is there a similar way to get the folder name directly? I couldn't find it
in ThisComponent, using xray.

I can easily get the name of the folder by adding a line like this:
FolderPath=Left(FilePath, InStr(FilePath, ThisComponent.getTitle())-2)

But that is not what my question is about…
I just don't like to calculate things if they are already known…


Johnny Rosenberg

Re: Basic macro – Retrieve folder of the current spreadsheet

Posted by Johnny Rosenberg <gu...@gmail.com>.
2013/9/29 Bernard Marcelly <ma...@club-internet.fr>

> Message de Johnny Rosenberg  date 2013-09-28 17:03 :
>
>
>> Is there a similar way to get the folder name directly? I couldn't find it
>>
>
> Not directly. But you can use a routine from the Tools library:
>
> Dim docFolder As String
>
> GlobalScope.BasicLibraries.loadLibrary("Tools")
> docFolder = DirectoryNameoutofPath(ThisComponent.URL, "/")
> MsgBox(docFolder, 0, "Folder of this document")
>

Thanks, that will be good enough.


>
> And, referring to your code, you don't need to ConvertToURL() what is
> already an URL address ;-)
>

Good, because I didn't. I converted FROM URL, not TO.  :P
ThisComponent.getURL() returns (for instance) ”file:///a/b%20c/d.e” and I
want ”/a/b c/d.e”, and that's what ConvertFromURL() does for me.
My code was not complete, I only brought the part relevant for my question.
What's going to happen with my path is that I'm going to use it to run a
Bash script from the macro, for instance Shell(MyCommand, 4, Parameters).
MyCommand could be something like
"/home/guraknugen/bin/SomeFancyScript.sh". In this particular case the
script is located in the same folder as the spreadsheet itself, that's why
I want the folder name of the spreadsheet.

For instance:
SpreadsheetFilename="/home/guraknugen/some/folder/MySpreadsheet.ods"
FolderName="/home/guraknugen/some/folder" ' Maybe using that
DirectoryNameOutOfPath() method
ScriptName=FolderName & "/DoThisAndThat.sh"

I always (well, almost always) organise my files and folders project-wise.
I don't have a folder with all my spreadsheets etc, because it just doesn't
make sense to me. It makes more sense to keep files that belong to the same
”project” together. Could be a spreadsheet, some images, maybe a couple of
sound files etc, organised in sub-folders to the project's folder. If I
want to see all my spreadsheets on the whole drive, I could always search
for .ods files in my home folder and its sub-folders. There could be a
point collecting all scripts at one place, but I can achieve that with
symbolic links.

Anyway, I think those Tools will be useful. Thanks for your help!


Johnny Rosenberg


>
> Regards
>   Bernard
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: api-unsubscribe@openoffice.apache.org
> For additional commands, e-mail: api-help@openoffice.apache.org
>
>

Re: Basic macro– Retrieve folder of the current spreadsheet

Posted by Bernard Marcelly <ma...@club-internet.fr>.
Message de Johnny Rosenberg  date 2013-09-28 17:03 :
>
> Is there a similar way to get the folder name directly? I couldn't find it

Not directly. But you can use a routine from the Tools library:

Dim docFolder As String

GlobalScope.BasicLibraries.loadLibrary("Tools")
docFolder = DirectoryNameoutofPath(ThisComponent.URL, "/")
MsgBox(docFolder, 0, "Folder of this document")

And, referring to your code, you don't need to ConvertToURL() what is already an 
URL address ;-)

Regards
   Bernard

---------------------------------------------------------------------
To unsubscribe, e-mail: api-unsubscribe@openoffice.apache.org
For additional commands, e-mail: api-help@openoffice.apache.org