Re: Re: Examining a directory with OpenOffice.org Basic
Ariel Constenla-Haile <[email protected]>
| Newsgroups | gmane.comp.openoffice.devel.api |
|---|---|
| Message-ID | <[email protected]> |
Hello Johnny, On Wednesday 01 December 2010, 10:38, Johnny Rosenberg wrote: > 2010/12/1 Johnny Rosenberg <[email protected]>: > > If I know the name of a directory, let's say ~/MyImages, how can I > > easily read the names of all the files in that directory? Let's say > > that we will fill an array with all the file names. > > > > I have searched a bit online, but so far I didn't find anything that I > > understand… I'll continue searching, though. > > He he he… I tried again to search for the answer and this time I found > it almost immediately… At least I think I did: > > http://wiki.services.openoffice.org/wiki/Documentation/BASIC_Guide/Files_an > d_Directories_(Runtime_Library) > > Seems to be what I am looking for. > > Other thoughts about this are still welcome, though. I'd prefer using OOo API (not simply OOo Basic). This way you can then port your code to any supported language. Try the following: REM ***** BASIC ***** Option Explicit Sub Main Dim oSFA as Object oSFA = CreateUnoService( "com.sun.star.ucb.SimpleFileAccess" ) Dim sURL$ sURL = getHomeDir() If NOT oSFA.exists( sURL) OR NOT oSFA.isFolder( sURL ) Then 'some message Exit Sub End If Dim sHomeDirFileContents$() Dim sHomeDirFolderContents$() sHomeDirFileContents = oSFA.getFolderContents( sURL, false ) sHomeDirFolderContents = oSFA.getFolderContents( sURL, true ) Dim oDoc as Object oDoc = StarDesktop.loadComponentFromURL(_ "private:factory/swriter", _ "_default", _ com.sun.star.frame.FrameSearchFlag.ALL, _ Array()) Dim oCursor as Object oCursor = oDoc.getText().createTextCursorByRange(oDoc.getText().getStart()) InsertContents( oCursor, sHomeDirFileContents, "Only files" ) InsertContents( oCursor, sHomeDirFolderContents, "Files and folders" ) End Sub Sub InsertContents( oCursor as Object, sContents(), sHeading$ ) oCursor.ParaStyleName = "Heading 1" oCursor.getText().insertString( oCursor, sHeading, false ) oCursor.getText().insertControlCharacter( oCursor, _ com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, false ) oCursor.ParaStyleName = "Default" Dim n% For n = 0 To UBound(sContents) oCursor.getText().insertString( oCursor, sContents(n), false ) oCursor.getText().insertControlCharacter( oCursor, _ com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, false ) Next End Sub Function getHomeDir() as String Dim oPaths oPaths = CreateUnoService("com.sun.star.util.PathSubstitution") getHomeDir() = oPaths.getSubstituteVariableValue("$(home)") End Function Regards -- Ariel Constenla-Haile La Plata, Argentina
signature.asc
(application/pgp-signature, 836 B)
-----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.16 (GNU/Linux) iQIcBAABCAAGBQJM9linAAoJEMjP1bm45QNWblIP/01c5z2DDINJzhjGq38JR32T u5NfYiliPwT5CXPfgWbJhwzmCjXpPityXqIReVdUNvWeRT03Rhbcsn/9WZFQ065V QwyaecVvld9ocLC1GxW3dybIBIasFMmom8yd/jI/+zXN25Xzv3wODLrirR4aqi+/ Xtqaa1Px2f/IBhXS+yGOiokFjS2MVes0Ur1LxT8lYY+B2YCLfksCJ1A18YLTQI3k dgMdiDi595xCRqzVajlLH3VDFcp2gJKIVE1blwzymao/6lN74v6mhuOiADs1P/ds RDF5ZBToof6F/vs7vAXHpfQDIxM9nfP1Yeo+9GhPBOSfgtT/Vm4eZyNLp9HYjoDP 2NFFXMD+Hz0AQE/KyGIY5L/thQ2XeeZsfI1QPUWUVO5wC/QEsSl16RqvqFaGB1gK WcVmG8Vg24BsJJv15fpOMm+sMs9v1ODMntnffg6Hs5uSRkcixsETjMgYJD5a/mGz feGZVGrvAGpJoHYHHzvBof85lwYmOEK9+sh7h1n5HHhWL656CbzevoB0SbzBkDqu ABhbHpkVb+wgSLEnMuD2fmm3kbUowhvH+4uRYsoiudLeWEWLwjk2qKjQOESfUeZK 93AInPo3OOEBM1iu/t7zno2bUWkuH1nKGfYQ9bqTi8BAZZ9YKtkm92UfDakG+i1X 2gy9AWQT1nM8BsqRFpq7 =0j1r -----END PGP SIGNATURE-----