summaryrefslogtreecommitdiffstats
path: root/wizards/source/scriptforge/SF_FileSystem.xba
blob: 39ea4888e3d11c0ec933bf87f7b282007b238693 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="SF_FileSystem" script:language="StarBasic" script:moduleType="normal">REM =======================================================================================================================
REM ===			The ScriptForge library and its associated libraries are part of the LibreOffice project.				===
REM ===					Full documentation is available on https://help.libreoffice.org/								===
REM =======================================================================================================================

Option Compatible
Option Explicit

&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;
&apos;&apos;&apos;	SF_FileSystem
&apos;&apos;&apos;	=============
&apos;&apos;&apos;		Class implementing the file system service
&apos;&apos;&apos;		for common file and folder handling routines
&apos;&apos;&apos;		Including copy and move of files and folders, with or without wildcards
&apos;&apos;&apos;		The design choices are largely inspired by
&apos;&apos;&apos;			https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/filesystemobject-object
&apos;&apos;&apos;			The File and Folder classes have been found redundant with the current class and have not been implemented
&apos;&apos;&apos;		The implementation is mainly based on the XSimpleFileAccess UNO interface
&apos;&apos;&apos;			https://api.libreoffice.org/docs/idl/ref/interfacecom_1_1sun_1_1star_1_1ucb_1_1XSimpleFileAccess.html
&apos;&apos;&apos;
&apos;&apos;&apos;		Subclasses:
&apos;&apos;&apos;			SF_TextStream
&apos;&apos;&apos;
&apos;&apos;&apos;		Definitions:
&apos;&apos;&apos;			File and folder names may be expressed either in the (preferable because portable) URL form
&apos;&apos;&apos;			or in the more usual operating system notation (e.g. C:\... for Windows)
&apos;&apos;&apos;			The notation, both for arguments and for returned values
&apos;&apos;&apos;			is determined by the FileNaming property: either &quot;URL&quot; (default) or &quot;SYS&quot;
&apos;&apos;&apos;
&apos;&apos;&apos;				FileName: the full name of the file including the path without any ending path separator
&apos;&apos;&apos;				FolderName: the full name of the folder including the path and the ending path separator
&apos;&apos;&apos;				Name: the last component of the File- or FolderName including its extension
&apos;&apos;&apos;				BaseName: the last component of the File- or FolderName without its extension
&apos;&apos;&apos;				NamePattern: any of the above names containing wildcards in its last component
&apos;&apos;&apos;					Admitted wildcards are:	the &quot;?&quot; represents any single character
&apos;&apos;&apos;											the &quot;*&quot; represents zero, one, or multiple characters
&apos;&apos;&apos;
&apos;&apos;&apos;		Service invocation example:
&apos;&apos;&apos;			Dim FSO As Variant
&apos;&apos;&apos;			Set FSO = CreateScriptService(&quot;FileSystem&quot;)
&apos;&apos;&apos;
&apos;&apos;&apos;		Detailed user documentation:
&apos;&apos;&apos;			https://help.libreoffice.org/latest/en-US/text/sbasic/shared/03/sf_filesystem.html?DbPAR=BASIC
&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;

REM ================================================================== EXCEPTIONS

Const UNKNOWNFILEERROR			=	&quot;UNKNOWNFILEERROR&quot;		&apos;	Source file does not exist
Const UNKNOWNFOLDERERROR		=	&quot;UNKNOWNFOLDERERROR&quot;	&apos;	Source folder or Destination folder does not exist
Const NOTAFILEERROR				=	&quot;NOTAFILEERROR&quot;			&apos;	Destination is a folder, not a file
Const NOTAFOLDERERROR			=	&quot;NOTAFOLDERERROR&quot;		&apos;	Destination is a file, not a folder
Const OVERWRITEERROR			=	&quot;OVERWRITEERROR&quot;		&apos;	Destination can not be overwritten
Const READONLYERROR				=	&quot;READONLYERROR&quot;			&apos;	Destination has its read-only attribute set
Const NOFILEMATCHERROR			=	&quot;NOFILEMATCHFOUND&quot;		&apos;	No file matches Source containing wildcards
Const FOLDERCREATIONERROR		=	&quot;FOLDERCREATIONERROR&quot;	&apos;	FolderName is an existing folder or file

REM ============================================================ MODULE CONSTANTS

&apos;&apos;&apos;	TextStream open modes
Const cstForReading				=	1
Const cstForWriting				=	2
Const cstForAppending			=	8

REM ===================================================== CONSTRUCTOR/DESTRUCTOR

REM -----------------------------------------------------------------------------
Public Function Dispose() As Variant
	Set Dispose = Nothing
End Function	&apos;	ScriptForge.SF_FileSystem Explicit destructor

REM ================================================================== PROPERTIES

REM -----------------------------------------------------------------------------
Property Get ConfigFolder() As String
&apos;&apos;&apos;	Return the configuration folder of LibreOffice

Const cstThisSub = &quot;FileSystem.getConfigFolder&quot;

	SF_Utils._EnterFunction(cstThisSub)
	ConfigFolder = SF_FileSystem._GetConfigFolder(&quot;user&quot;)
	SF_Utils._ExitFunction(cstThisSub)

End Property	&apos;	ScriptForge.SF_FileSystem.ConfigFolder

REM -----------------------------------------------------------------------------
Property Get ExtensionsFolder() As String
&apos;&apos;&apos;	Return the folder containing the extensions installed for the current user

Dim oMacro As Object		&apos;	/singletons/com.sun.star.util.theMacroExpander
Const cstThisSub = &quot;FileSystem.getExtensionsFolder&quot;

	SF_Utils._EnterFunction(cstThisSub)
	Set oMacro = SF_Utils._GetUNOService(&quot;MacroExpander&quot;)
	ExtensionsFolder = SF_FileSystem._ConvertFromUrl(oMacro.ExpandMacros(&quot;$UNO_USER_PACKAGES_CACHE&quot;) &amp; &quot;/&quot;)
	SF_Utils._ExitFunction(cstThisSub)

End Property	&apos;	ScriptForge.SF_FileSystem.ExtensionsFolder

REM -----------------------------------------------------------------------------
Property Get FileNaming() As Variant
&apos;&apos;&apos;	Return the current files and folder notation, either &quot;ANY&quot;, &quot;URL&quot; or &quot;SYS&quot;
&apos;&apos;&apos;		&quot;ANY&quot;: methods receive either URL or native file names, but always return URL file names
&apos;&apos;&apos;		&quot;URL&quot;: methods expect URL arguments and return URL strings (when relevant)
&apos;&apos;&apos;		&quot;SYS&quot;: idem but operating system notation

Const cstThisSub = &quot;FileSystem.getFileNaming&quot;
	SF_Utils._EnterFunction(cstThisSub)
	FileNaming = _SF_.FileSystemNaming
	SF_Utils._ExitFunction(cstThisSub)

End Property	&apos;	ScriptForge.SF_FileSystem.FileNaming (get)

REM -----------------------------------------------------------------------------
Property Let FileNaming(ByVal pvNotation As Variant)
&apos;&apos;&apos;	Set the files and folders notation: &quot;ANY&quot;, &quot;URL&quot; or &quot;SYS&quot;

Const cstThisSub = &quot;FileSystem.setFileNaming&quot;
	SF_Utils._EnterFunction(cstThisSub)
	If VarType(pvNotation) = V_STRING Then
		Select Case UCase(pvNotation)
			Case &quot;ANY&quot;, &quot;URL&quot;, &quot;SYS&quot;	:	_SF_.FileSystemNaming = UCase(pvNotation)
			Case Else	&apos;	Unchanged
		End Select
	End If
	SF_Utils._ExitFunction(cstThisSub)

End Property	&apos;	ScriptForge.SF_FileSystem.FileNaming (let)

REM -----------------------------------------------------------------------------
Property Get ForAppending As Integer
&apos;&apos;&apos;	Convenient constant (see documentation)
	ForAppending = cstForAppending
End Property	&apos;	ScriptForge.SF_FileSystem.ForAppending

REM -----------------------------------------------------------------------------
Property Get ForReading As Integer
&apos;&apos;&apos;	Convenient constant (see documentation)
	ForReading = cstForReading
End Property	&apos;	ScriptForge.SF_FileSystem.ForReading

REM -----------------------------------------------------------------------------
Property Get ForWriting As Integer
&apos;&apos;&apos;	Convenient constant (see documentation)
	ForWriting = cstForWriting
End Property	&apos;	ScriptForge.SF_FileSystem.ForWriting

REM -----------------------------------------------------------------------------
Property Get HomeFolder() As String
&apos;&apos;&apos;	Return the user home folder

Const cstThisSub = &quot;FileSystem.getHomeFolder&quot;

	SF_Utils._EnterFunction(cstThisSub)
	HomeFolder = SF_FileSystem._GetConfigFolder(&quot;home&quot;)
	SF_Utils._ExitFunction(cstThisSub)

End Property	&apos;	ScriptForge.SF_FileSystem.HomeFolder

REM -----------------------------------------------------------------------------
Property Get InstallFolder() As String
&apos;&apos;&apos;	Return the installation folder of LibreOffice

Const cstThisSub = &quot;FileSystem.getInstallFolder&quot;

	SF_Utils._EnterFunction(cstThisSub)
	InstallFolder = SF_FileSystem._GetConfigFolder(&quot;inst&quot;)
	SF_Utils._ExitFunction(cstThisSub)

End Property	&apos;	ScriptForge.SF_FileSystem.InstallFolder

REM -----------------------------------------------------------------------------
Property Get ObjectType As String
&apos;&apos;&apos;	Only to enable object representation
	ObjectType = &quot;SF_FileSystem&quot;
End Property	&apos;	ScriptForge.SF_FileSystem.ObjectType

REM -----------------------------------------------------------------------------
Property Get ServiceName As String
&apos;&apos;&apos;	Internal use
	ServiceName = &quot;ScriptForge.FileSystem&quot;
End Property	&apos;	ScriptForge.SF_FileSystem.ServiceName

REM -----------------------------------------------------------------------------
Property Get TemplatesFolder() As String
&apos;&apos;&apos;	Return the folder defined in the LibreOffice paths options as intended for templates files

Dim sPath As String			&apos;	Template property of com.sun.star.util.PathSettings
Const cstThisSub = &quot;FileSystem.getTemplatesFolder&quot;

	SF_Utils._EnterFunction(cstThisSub)
	sPath = SF_Utils._GetUNOService(&quot;PathSettings&quot;).Template
	TemplatesFolder = SF_FileSystem._ConvertFromUrl(Split(sPath, &quot;;&quot;)(0) &amp; &quot;/&quot;)
	SF_Utils._ExitFunction(cstThisSub)

End Property	&apos;	ScriptForge.SF_FileSystem.TemplatesFolder

REM -----------------------------------------------------------------------------
Property Get TemporaryFolder() As String
&apos;&apos;&apos;	Return the folder defined in the LibreOffice paths options as intended for temporary files

Const cstThisSub = &quot;FileSystem.getTemporaryFolder&quot;

	SF_Utils._EnterFunction(cstThisSub)
	TemporaryFolder = SF_FileSystem._GetConfigFolder(&quot;temp&quot;)
	SF_Utils._ExitFunction(cstThisSub)

End Property	&apos;	ScriptForge.SF_FileSystem.TemporaryFolder

REM -----------------------------------------------------------------------------
Property Get UserTemplatesFolder() As String
&apos;&apos;&apos;	Return the folder defined in the LibreOffice paths options as intended for User templates files

Dim sPath As String			&apos;	Template_writable property of com.sun.star.util.PathSettings
Const cstThisSub = &quot;FileSystem.getUserTemplatesFolder&quot;

	SF_Utils._EnterFunction(cstThisSub)
	sPath = SF_Utils._GetUNOService(&quot;PathSettings&quot;).Template_writable
	UserTemplatesFolder = SF_FileSystem._ConvertFromUrl(sPath &amp; &quot;/&quot;)
	SF_Utils._ExitFunction(cstThisSub)

End Property	&apos;	ScriptForge.SF_FileSystem.UserTemplatesFolder

REM ===================================================================== METHODS

REM -----------------------------------------------------------------------------
Public Function BuildPath(Optional ByVal FolderName As Variant _
							, Optional ByVal Name As Variant _
							) As String
&apos;&apos;&apos;	Combines a folder path and the name of a file and returns the combination with a valid path separator
&apos;&apos;&apos;	Inserts an additional path separator between the foldername and the name, only if necessary
&apos;&apos;&apos;	Args:
&apos;&apos;&apos;		FolderName: Path with which Name is combined. Path need not specify an existing folder
&apos;&apos;&apos;		Name: To be appended to the existing path.
&apos;&apos;&apos;	Returns:
&apos;&apos;&apos;		The path concatenated with the file name after insertion of a path separator, if necessary
&apos;&apos;&apos;	Example:
&apos;&apos;&apos;		Dim a As String
&apos;&apos;&apos;		    FSO.FileNaming = &quot;SYS&quot;
&apos;&apos;&apos;			a = FSO.BuildPath(&quot;C:\Windows&quot;, &quot;Notepad.exe&quot;) returns C:\Windows\Notepad.exe

Dim sBuild As String			&apos;	Return value
Dim sFile As String				&apos;	Alias for Name
Const cstFileProtocol = &quot;file:///&quot;
Const cstThisSub = &quot;FileSystem.BuildPath&quot;
Const cstSubArgs = &quot;FolderName, Name&quot;

	If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
	sBuild = &quot;&quot;

Check:
	If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
		If Not SF_Utils._ValidateFile(FolderName, &quot;FolderName&quot;) Then GoTo Finally
		If Not SF_Utils._Validate(Name, &quot;Name&quot;, V_STRING) Then GoTo Finally
	End If
	FolderName = SF_FileSystem._ConvertToUrl(FolderName)

Try:
	&apos;	Add separator if necessary. FolderName is now in URL notation
	If Len(FolderName) &gt; 0 Then
		If Right(FolderName, 1) &lt;&gt; &quot;/&quot; Then sBuild = FolderName &amp; &quot;/&quot; Else sBuild = FolderName
	Else
		sBuild = cstFileProtocol
	End If
	&apos;	Encode the file name
	sFile = ConvertToUrl(Name)
	&apos;	Some file names produce http://file.name.suffix/
	If Left(sFile, 7) = &quot;http://&quot; Then sFile = cstFileProtocol &amp; Mid(sFile, 8, Len(sFile) - 8)
	&apos;	Combine both parts
	If Left(sFile, Len(cstFileProtocol)) = cstFileProtocol Then sBuild = sBuild &amp; Mid(sFile, Len(cstFileProtocol) + 1) Else sBuild = sBuild &amp; sFile
 
Finally:
	BuildPath = SF_FileSystem._ConvertFromUrl(sBuild)
	SF_Utils._ExitFunction(cstThisSub)
	Exit Function
Catch:
	GoTo Finally
End Function	&apos;	ScriptForge.SF_FileSystem.BuildPath

REM -----------------------------------------------------------------------------
Public Function CompareFiles(Optional ByVal FileName1 As Variant _
								, Optional ByVal FileName2 As Variant _
								, Optional ByVal CompareContents As Variant _
								)
&apos;&apos;&apos;	Compare 2 files and return True if they seem identical
&apos;&apos;&apos;	The comparison may be based on the file attributes, like modification time,
&apos;&apos;&apos;	or on their contents.
&apos;&apos;&apos;	Args:
&apos;&apos;&apos;		FileName1: The 1st file to compare
&apos;&apos;&apos;		FileName2: The 2nd file to compare
&apos;&apos;&apos;		CompareContents: When True, the contents of the files are compared. Default = False
&apos;&apos;&apos;	Returns:
&apos;&apos;&apos;		True when the files seem identical
&apos;&apos;&apos;	Exceptions:
&apos;&apos;&apos;		UNKNOWNFILEERROR		One of the files does not exist
&apos;&apos;&apos;	Example:
&apos;&apos;&apos;		FSO.FileNaming = &quot;SYS&quot;
&apos;&apos;&apos;		MsgBox FSO.CompareFiles(&quot;C:\myFile1.txt&quot;, &quot;C:\myFile2.txt&quot;, CompareContents := True)

Dim bCompare As Boolean			&apos;	Return value
Dim sFile As String				&apos;	Alias of FileName1 and 2
Dim iFile As Integer			&apos;	1 or 2
Const cstPyHelper = &quot;$&quot; &amp; &quot;_SF_FileSystem__CompareFiles&quot;

Const cstThisSub = &quot;FileSystem.CompareFiles&quot;
Const cstSubArgs = &quot;FileName1, FileName2, [CompareContents=False]&quot;

	If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
	bCompare = False

Check: 
	If IsMissing(CompareContents) Or IsEmpty(CompareContents) Then CompareContents = False
	If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
		If Not SF_Utils._ValidateFile(FileName1, &quot;FileName1&quot;, False) Then GoTo Finally
		If Not SF_Utils._ValidateFile(FileName2, &quot;FileName2&quot;, False) Then GoTo Finally
		If Not SF_Utils._Validate(CompareContents, &quot;CompareContents&quot;, V_BOOLEAN) Then GoTo Finally
	End If
	&apos;	Do the files exist ? Otherwise raise error
	sFile = FileName1	:	iFile = 1
	If Not SF_FileSystem.FileExists(sFile) Then GoTo CatchNotExists
	sFile = FileName2	:	iFile = 2
	If Not SF_FileSystem.FileExists(sFile) Then GoTo CatchNotExists

Try:
	With ScriptForge.SF_Session
		bCompare = .ExecutePythonScript(.SCRIPTISSHARED, _SF_.PythonHelper &amp; cstPyHelper _
							, _ConvertFromUrl(FileName1) _
							, _ConvertFromUrl(FileName2) _
							, CompareContents)
	End With

Finally:
	CompareFiles = bCompare
	SF_Utils._ExitFunction(cstThisSub)
	Exit Function
Catch:
	GoTo Finally
CatchNotExists:
	SF_Exception.RaiseFatal(UNKNOWNFILEERROR, &quot;FileName&quot; &amp; iFile, sFile)
	GoTo Finally
End Function    &apos;   ScriptForge.SF_FileSystem.CompareFiles

REM -----------------------------------------------------------------------------
Public Function CopyFile(Optional ByVal Source As Variant _
							, Optional ByVal Destination As Variant _
							, Optional ByVal Overwrite As Variant _
							) As Boolean
&apos;&apos;&apos;	Copies one or more files from one location to another
&apos;&apos;&apos;	Args:
&apos;&apos;&apos;		Source: FileName or NamePattern which can include wildcard characters, for one or more files to be copied
&apos;&apos;&apos;		Destination:	FileName where the single Source file is to be copied
&apos;&apos;&apos;					or	FolderName where the multiple files from Source are to be copied
&apos;&apos;&apos;							If FolderName does not exist, it is created
&apos;&apos;&apos;					Anyway, wildcard characters are not allowed in Destination
&apos;&apos;&apos;		Overwrite: If True (default), files may be overwritten
&apos;&apos;&apos;			CopyFile will fail if Destination has the read-only attribute set, regardless of the value of Overwrite.
&apos;&apos;&apos;	Returns:
&apos;&apos;&apos;		True if at least one file has been copied
&apos;&apos;&apos;		False if an error occurred
&apos;&apos;&apos;			An error also occurs if a source using wildcard characters doesn&apos;t match any files.
&apos;&apos;&apos;			The method stops on the first error it encounters
&apos;&apos;&apos;			No attempt is made to roll back or undo any changes made before an error occurs
&apos;&apos;&apos;	Exceptions:
&apos;&apos;&apos;		UNKNOWNFILEERROR			Source does not exist
&apos;&apos;&apos;		UNKNOWNFOLDERERROR			Source folder or Destination folder does not exist
&apos;&apos;&apos;		NOFILEMATCHERROR		No file matches Source containing wildcards
&apos;&apos;&apos;		NOTAFOLDERERROR				Destination is a file, not a folder
&apos;&apos;&apos;		NOTAFILEERROR				Destination is a folder, not a file
&apos;&apos;&apos;		OVERWRITEERROR				Destination can not be overwritten
&apos;&apos;&apos;		READONLYERROR				Destination has its read-only attribute set
&apos;&apos;&apos;	Example:
&apos;&apos;&apos;		FSO.FileNaming = &quot;SYS&quot;
&apos;&apos;&apos;		FSO.CopyFile(&quot;C:\Windows\*.*&quot;, &quot;C:\Temp\&quot;, Overwrite := False)		&apos;	Only files are copied, subfolders are not

Dim bCopy As Boolean			&apos;	Return value

Const cstThisSub = &quot;FileSystem.CopyFile&quot;
Const cstSubArgs = &quot;Source, Destination, [Overwrite=True]&quot;

	If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
	bCopy = False

Check: 
	If IsMissing(Overwrite) Or IsEmpty(Overwrite) Then Overwrite = True
	If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
		If Not SF_Utils._ValidateFile(Source, &quot;Source&quot;, True) Then GoTo Finally
		If Not SF_Utils._ValidateFile(Destination, &quot;Destination&quot;, False) Then GoTo Finally
		If Not SF_Utils._Validate(Overwrite, &quot;Overwrite&quot;, V_BOOLEAN) Then GoTo Finally
	End If

Try:
	bCopy = SF_FileSystem._CopyMove(&quot;CopyFile&quot;, Source, Destination, Overwrite)

Finally:
	CopyFile = bCopy
	SF_Utils._ExitFunction(cstThisSub)
	Exit Function
Catch:
	GoTo Finally
End Function    &apos;   ScriptForge.SF_FileSystem.CopyFile

REM -----------------------------------------------------------------------------
Public Function CopyFolder(Optional ByVal Source As Variant _
							, Optional ByVal Destination As Variant _
							, Optional ByVal Overwrite As Variant _
							) As Boolean
&apos;&apos;&apos;	Copies one or more folders from one location to another
&apos;&apos;&apos;	Args:
&apos;&apos;&apos;		Source: FolderName or NamePattern which can include wildcard characters, for one or more folders to be copied
&apos;&apos;&apos;		Destination:	FolderName where the single Source folder is to be copied
&apos;&apos;&apos;					or	FolderName where the multiple folders from Source are to be copied
&apos;&apos;&apos;							If FolderName does not exist, it is created
&apos;&apos;&apos;					Anyway, wildcard characters are not allowed in Destination
&apos;&apos;&apos;		Overwrite: If True (default), folders and their content may be overwritten
&apos;&apos;&apos;			CopyFile will fail if Destination has the read-only attribute set, regardless of the value of Overwrite.
&apos;&apos;&apos;	Returns:
&apos;&apos;&apos;		True if at least one folder has been copied
&apos;&apos;&apos;		False if an error occurred
&apos;&apos;&apos;			An error also occurs if a source using wildcard characters doesn&apos;t match any folders.
&apos;&apos;&apos;			The method stops on the first error it encounters
&apos;&apos;&apos;			No attempt is made to roll back or undo any changes made before an error occurs
&apos;&apos;&apos;	Exceptions:
&apos;&apos;&apos;		UNKNOWNFILEERROR			Source does not exist
&apos;&apos;&apos;		UNKNOWNFOLDERERROR			Source folder or Destination folder does not exist
&apos;&apos;&apos;		NOFILEMATCHERROR		No file matches Source containing wildcards
&apos;&apos;&apos;		NOTAFOLDERERROR				Destination is a file, not a folder
&apos;&apos;&apos;		OVERWRITEERROR				Destination can not be overwritten
&apos;&apos;&apos;		READONLYERROR				Destination has its read-only attribute set
&apos;&apos;&apos;	Example:
&apos;&apos;&apos;		FSO.FileNaming = &quot;SYS&quot;
&apos;&apos;&apos;		FSO.CopyFolder(&quot;C:\Windows\*&quot;, &quot;C:\Temp\&quot;, Overwrite := False)

Dim bCopy As Boolean			&apos;	Return value

Const cstThisSub = &quot;FileSystem.CopyFolder&quot;
Const cstSubArgs = &quot;Source, Destination, [Overwrite=True]&quot;

	If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
	bCopy = False

Check: 
	If IsMissing(Overwrite) Or IsEmpty(Overwrite) Then Overwrite = True
	If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
		If Not SF_Utils._ValidateFile(Source, &quot;Source&quot;, True) Then GoTo Finally
		If Not SF_Utils._ValidateFile(Destination, &quot;Destination&quot;, False) Then GoTo Finally
		If Not SF_Utils._Validate(Overwrite, &quot;Overwrite&quot;, V_BOOLEAN) Then GoTo Finally
	End If

Try:
	bCopy = SF_FileSystem._CopyMove(&quot;CopyFolder&quot;, Source, Destination, Overwrite)

Finally:
	CopyFolder = bCopy
	SF_Utils._ExitFunction(cstThisSub)
	Exit Function
Catch:
	GoTo Finally
End Function    &apos;   ScriptForge.SF_FileSystem.CopyFolder

REM -----------------------------------------------------------------------------
Public Function CreateFolder(Optional ByVal FolderName As Variant) As Boolean
&apos;&apos;&apos;	Return True if the given folder name could be created successfully
&apos;&apos;&apos;	The parent folder does not need to exist beforehand
&apos;&apos;&apos;	Args:
&apos;&apos;&apos;		FolderName: a string representing the folder to create. It must not exist
&apos;&apos;&apos;	Returns:
&apos;&apos;&apos;		True if FolderName is a valid folder name, does not exist and creation was successful
&apos;&apos;&apos;		False otherwise including when FolderName is a file
&apos;&apos;&apos;	Exceptions:
&apos;&apos;&apos;		FOLDERCREATIONERROR		FolderName is an existing folder or file
&apos;&apos;&apos;	Example:
&apos;&apos;&apos;		FSO.FileNaming = &quot;SYS&quot;
&apos;&apos;&apos;		FSO.CreateFolder(&quot;C:\NewFolder\&quot;)

Dim bCreate As Boolean			&apos;	Return value
Dim oSfa As Object				&apos;	com.sun.star.ucb.SimpleFileAccess

Const cstThisSub = &quot;FileSystem.CreateFolder&quot;
Const cstSubArgs = &quot;FolderName&quot;

	If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
	bCreate = False

Check:
	If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
		If Not SF_Utils._ValidateFile(FolderName, &quot;FolderName&quot;) Then GoTo Finally
	End If

Try:
	Set oSfa = SF_Utils._GetUnoService(&quot;FileAccess&quot;)
	If SF_FileSystem.FolderExists(FolderName) Then GoTo CatchExists
	If SF_FileSystem.FileExists(FolderName) Then GoTo CatchExists
	oSfa.createFolder(SF_FileSystem._ConvertToUrl(FolderName))
	bCreate = True

Finally:
	CreateFolder = bCreate
	SF_Utils._ExitFunction(cstThisSub)
	Exit Function
Catch:
	GoTo Finally
CatchExists:
	SF_Exception.RaiseFatal(FOLDERCREATIONERROR, &quot;FolderName&quot;, FolderName)
	GoTo Finally
End Function    &apos;   ScriptForge.SF_FileSystem.CreateFolder

REM -----------------------------------------------------------------------------
Public Function CreateTextFile(Optional ByVal FileName As Variant _
								, Optional ByVal Overwrite As Variant _
								, Optional ByVal Encoding As Variant _
								) As Object
&apos;&apos;&apos;	Creates a specified file and returns a TextStream object that can be used to write to the file
&apos;&apos;&apos;	Args:
&apos;&apos;&apos;		FileName: Identifies the file to create
&apos;&apos;&apos;		Overwrite: Boolean value that indicates if an existing file can be overwritten (default = True)
&apos;&apos;&apos;		Encoding: The character set that should be used
&apos;&apos;&apos;				Use one of the Names listed in https://www.iana.org/assignments/character-sets/character-sets.xhtml
&apos;&apos;&apos;				Note that LibreOffice does not implement all existing sets
&apos;&apos;&apos;				Default = UTF-8
&apos;&apos;&apos;	Returns:
&apos;&apos;&apos;		An instance of the SF_TextStream class representing the opened file or a Null object if an error occurred
&apos;&apos;&apos;		It doesn&apos;t check either if the given encoding is implemented in LibreOffice
&apos;&apos;&apos;	Exceptions:
&apos;&apos;&apos;		OVERWRITEERROR			File exists, creation impossible
&apos;&apos;&apos;	Example:
&apos;&apos;&apos;		Dim myFile As Object
&apos;&apos;&apos;		    FSO.FileNaming = &quot;SYS&quot;
&apos;&apos;&apos;			Set myFile = FSO.CreateTextFile(&quot;C:\Temp\ThisFile.txt&quot;, Overwrite := True)

Dim oTextStream As Object		&apos;	Return value
Const cstThisSub = &quot;FileSystem.CreateTextFile&quot;
Const cstSubArgs = &quot;FileName, [Overwrite=True], [Encoding=&quot;&quot;UTF-8&quot;&quot;]&quot;

	If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
	Set oTextStream = Nothing

Check:
	If IsMissing(Overwrite) Or IsEmpty(Overwrite) Then Overwrite = True
	If IsMissing(Encoding) Or IsEmpty(Encoding) Then Encoding = &quot;UTF-8&quot;
	If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
		If Not SF_Utils._ValidateFile(FileName, &quot;FileName&quot;) Then GoTo Finally
		If Not SF_Utils._Validate(Overwrite, &quot;Overwrite&quot;, V_BOOLEAN) Then GoTo Finally
		If Not SF_Utils._Validate(Encoding, &quot;Encoding&quot;, V_STRING) Then GoTo Finally
	End If

	With SF_FileSystem
		If .FileExists(FileName) Then
			If Overwrite Then .DeleteFile(FileName) Else GoTo CatchOverWrite
		End If

Try:
		Set oTextStream = .OpenTextFile(FileName, .ForWriting, Create := True, Encoding := Encoding)
	End With

Finally:
	Set CreateTextFile = oTextStream
	SF_Utils._ExitFunction(cstThisSub)
	Exit Function
Catch:
	GoTo Finally
CatchOverWrite:
	SF_Exception.RaiseFatal(OVERWRITEERROR, &quot;FileName&quot;, FileName)
	GoTo Finally
End Function	&apos;	ScriptForge.SF_FileSystem.CreateTextFile

REM -----------------------------------------------------------------------------
Public Function DeleteFile(Optional ByVal FileName As Variant) As Boolean
&apos;&apos;&apos;	Deletes one or more files
&apos;&apos;&apos;	Args:
&apos;&apos;&apos;		FileName: FileName or NamePattern which can include wildcard characters, for one or more files to be deleted
&apos;&apos;&apos;	Returns:
&apos;&apos;&apos;		True if at least one file has been deleted
&apos;&apos;&apos;		False if an error occurred
&apos;&apos;&apos;			An error also occurs if a FileName using wildcard characters doesn&apos;t match any files.
&apos;&apos;&apos;			The method stops on the first error it encounters
&apos;&apos;&apos;			No attempt is made to roll back or undo any changes made before an error occurs
&apos;&apos;&apos;	Exceptions:
&apos;&apos;&apos;		UNKNOWNFILEERROR			FileName does not exist
&apos;&apos;&apos;		NOFILEMATCHERROR		No file matches FileName containing wildcards
&apos;&apos;&apos;		NOTAFILEERROR				Argument is a folder, not a file
&apos;&apos;&apos;	Example:
&apos;&apos;&apos;		FSO.FileNaming = &quot;SYS&quot;
&apos;&apos;&apos;		FSO.DeleteFile(&quot;C:\Temp\*.*&quot;)		&apos;	Only files are deleted, subfolders are not

Dim bDelete As Boolean			&apos;	Return value

Const cstThisSub = &quot;FileSystem.DeleteFile&quot;
Const cstSubArgs = &quot;FileName&quot;

	If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
	bDelete = False

Check: 
	If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
		If Not SF_Utils._ValidateFile(FileName, &quot;FileName&quot;, True) Then GoTo Finally
	End If

Try:
	bDelete = SF_FileSystem._Delete(&quot;DeleteFile&quot;, FileName)

Finally:
	DeleteFile = bDelete
	SF_Utils._ExitFunction(cstThisSub)
	Exit Function
Catch:
	GoTo Finally
End Function    &apos;   ScriptForge.SF_FileSystem.DeleteFile

REM -----------------------------------------------------------------------------
Public Function DeleteFolder(Optional ByVal FolderName As Variant) As Boolean
&apos;&apos;&apos;	Deletes one or more Folders
&apos;&apos;&apos;	Args:
&apos;&apos;&apos;		FolderName: FolderName or NamePattern which can include wildcard characters, for one or more Folders to be deleted
&apos;&apos;&apos;	Returns:
&apos;&apos;&apos;		True if at least one folder has been deleted
&apos;&apos;&apos;		False if an error occurred
&apos;&apos;&apos;			An error also occurs if a FolderName using wildcard characters doesn&apos;t match any folders.
&apos;&apos;&apos;			The method stops on the first error it encounters
&apos;&apos;&apos;			No attempt is made to roll back or undo any changes made before an error occurs
&apos;&apos;&apos;	Exceptions:
&apos;&apos;&apos;		UNKNOWNFOLDERERROR			FolderName does not exist
&apos;&apos;&apos;		NOFILEMATCHERROR		No folder matches FolderName containing wildcards
&apos;&apos;&apos;		NOTAFOLDERERROR				Argument is a file, not a folder
&apos;&apos;&apos;	Example:
&apos;&apos;&apos;		FSO.FileNaming = &quot;SYS&quot;
&apos;&apos;&apos;		FSO.DeleteFolder(&quot;C:\Temp\*&quot;)		&apos;	Only folders are deleted, files in the parent folder are not

Dim bDelete As Boolean			&apos;	Return value

Const cstThisSub = &quot;FileSystem.DeleteFolder&quot;
Const cstSubArgs = &quot;FolderName&quot;

	If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
	bDelete = False

Check: 
	If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
		If Not SF_Utils._ValidateFile(FolderName, &quot;FolderName&quot;, True) Then GoTo Finally
	End If

Try:
	bDelete = SF_FileSystem._Delete(&quot;DeleteFolder&quot;, FolderName)

Finally:
	DeleteFolder = bDelete
	SF_Utils._ExitFunction(cstThisSub)
	Exit Function
Catch:
	GoTo Finally
End Function    &apos;   ScriptForge.SF_FileSystem.DeleteFolder

REM -----------------------------------------------------------------------------
Public Function ExtensionFolder(Optional ByVal Extension As Variant) As String
&apos;&apos;&apos;	Return the folder where the given extension is installed. The argument must
&apos;&apos;&apos;	be in the list of extensions provided by the SF_Platform.Extensions property
&apos;&apos;&apos;	Args:
&apos;&apos;&apos;		Extension: a valid extension name
&apos;&apos;&apos;	Returns:
&apos;&apos;&apos;		The requested folder using the FileNaming notation
&apos;&apos;&apos;	Example:
&apos;&apos;&apos;		MsgBox FSO.ExtensionFolder(&quot;apso.python.script.organizer&quot;)

Dim sFolder As String			&apos;	Return value
Static vExtensions As Variant	&apos;	Cached list of existing extension names
Dim oPackage As Object			&apos;	/singletons/com.sun.star.deployment.PackageInformationProvider
Const cstThisSub = &quot;FileSystem.ExtensionFolder&quot;
Const cstSubArgs = &quot;Extension&quot;

	If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
	sFolder = &quot;&quot;

Check:
	If IsEmpty(vExtensions) Then vExtensions = SF_Platform.Extensions
	If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
		If Not SF_Utils._Validate(Extension, &quot;Extension&quot;, V_STRING, vExtensions) Then GoTo Finally
	End If

Try:
	&apos;	Search an individual folder
	Set oPackage = SF_Utils._GetUnoService(&quot;PackageInformationProvider&quot;)
	sFolder = oPackage.getPackageLocation(Extension)
 
Finally:
	ExtensionFolder = SF_FileSystem._ConvertFromUrl(sFolder)
	SF_Utils._ExitFunction(cstThisSub)
	Exit Function
Catch:
	GoTo Finally
End Function	&apos;	ScriptForge.SF_FileSystem.ExtensionFolder

REM -----------------------------------------------------------------------------
Public Function FileExists(Optional ByVal FileName As Variant) As Boolean
&apos;&apos;&apos;	Return True if the given file exists
&apos;&apos;&apos;	Args:
&apos;&apos;&apos;		FileName: a string representing a file
&apos;&apos;&apos;	Returns:
&apos;&apos;&apos;		True if FileName is a valid File name and it exists
&apos;&apos;&apos;		False otherwise including when FileName is a folder
&apos;&apos;&apos;	Example:
&apos;&apos;&apos;		FSO.FileNaming = &quot;SYS&quot;
&apos;&apos;&apos;		If FSO.FileExists(&quot;C:\Notepad.exe&quot;) Then ...

Dim bExists As Boolean			&apos;	Return value
Dim oSfa As Object				&apos;	com.sun.star.ucb.SimpleFileAccess

Const cstThisSub = &quot;FileSystem.FileExists&quot;
Const cstSubArgs = &quot;FileName&quot;

	If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
	bExists = False

Check:
	If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
		If Not SF_Utils._ValidateFile(FileName, &quot;FileName&quot;) Then GoTo Finally
	End If
	FileName = SF_FileSystem._ConvertToUrl(FileName)

Try:
	Set oSfa = SF_Utils._GetUnoService(&quot;FileAccess&quot;)
	bExists = oSfa.exists(FileName) And Not oSfa.isFolder(FileName)

Finally:
	FileExists = bExists
	SF_Utils._ExitFunction(cstThisSub)
	Exit Function
Catch:
	GoTo Finally
End Function    &apos;   ScriptForge.SF_FileSystem.FileExists

REM -----------------------------------------------------------------------------
Public Function Files(Optional ByVal FolderName As Variant _
						, Optional ByVal Filter As Variant _
						) As Variant
&apos;&apos;&apos;	Return an array of the FileNames stored in the given folder. The folder must exist
&apos;&apos;&apos;	Args:
&apos;&apos;&apos;		FolderName: the folder to explore
&apos;&apos;&apos;		Filter: contains wildcards (&quot;?&quot; and &quot;*&quot;) to limit the list to the relevant files (default = &quot;&quot;)
&apos;&apos;&apos;	Returns:
&apos;&apos;&apos;		An array of strings, each entry is the FileName of an existing file
&apos;&apos;&apos;	Exceptions:
&apos;&apos;&apos;		UNKNOWNFOLDERERROR		Folder does not exist
&apos;&apos;&apos;		NOTAFOLDERERROR			FolderName is a file, not a folder
&apos;&apos;&apos;	Example:
&apos;&apos;&apos;		Dim a As Variant
&apos;&apos;&apos;			FSO.FileNaming = &quot;SYS&quot;
&apos;&apos;&apos;			a = FSO.Files(&quot;C:\Windows\&quot;)

Dim vFiles As Variant			&apos;	Return value
Dim oSfa As Object				&apos;	com.sun.star.ucb.SimpleFileAccess
Dim sFolderName As String		&apos;	URL lias for FolderName
Dim sFile As String				&apos;	Single file
Dim i As Long

Const cstThisSub = &quot;FileSystem.Files&quot;
Const cstSubArgs = &quot;FolderName, [Filter=&quot;&quot;&quot;&quot;]&quot;

	If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
	vFiles = Array()

Check:
	If IsMissing(Filter) Or IsEmpty(Filter) Then Filter = &quot;&quot;
	If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
		If Not SF_Utils._ValidateFile(FolderName, &quot;FolderName&quot;) Then GoTo Finally
		If Not SF_Utils._Validate(Filter, &quot;Filter&quot;, V_STRING) Then GoTo Finally
	End If
	sFolderName = SF_FileSystem._ConvertToUrl(FolderName)
	If SF_FileSystem.FileExists(FolderName) Then GoTo CatchFile				&apos; Must not be a file
	If Not SF_FileSystem.FolderExists(FolderName) Then GoTo CatchFolder		&apos; Folder must exist

Try:
	&apos;	Get files
	Set oSfa = SF_Utils._GetUnoService(&quot;FileAccess&quot;)
	vFiles = oSfa.getFolderContents(sFolderName, False)
	&apos;	Adjust notations
	For i = 0 To UBound(vFiles)
		sFile = SF_FileSystem._ConvertFromUrl(vFiles(i))
		vFiles(i) = sFile
	Next i
	&apos;	Reduce list to those passing the filter
	If Len(Filter) &gt; 0 Then
		For i = 0 To UBound(vFiles)
			sFile = SF_FileSystem.GetName(vFiles(i))
			If Not SF_String.IsLike(sFile, Filter) Then vFiles(i) = &quot;&quot;
		Next i
		vFiles = Sf_Array.TrimArray(vFiles)
	End If

Finally:
	Files = vFiles
	SF_Utils._ExitFunction(cstThisSub)
	Exit Function
Catch:
	GoTo Finally
CatchFile:
	SF_Exception.RaiseFatal(NOTAFOLDERERROR, &quot;FolderName&quot;, FolderName)
	GoTo Finally
CatchFolder:
	SF_Exception.RaiseFatal(UNKNOWNFOLDERERROR, &quot;FolderName&quot;, FolderName)
	GoTo Finally
End Function    &apos;   ScriptForge.SF_FileSystem.Files

REM -----------------------------------------------------------------------------
Public Function FolderExists(Optional ByVal FolderName As Variant) As Boolean
&apos;&apos;&apos;	Return True if the given folder name exists
&apos;&apos;&apos;	Args:
&apos;&apos;&apos;		FolderName: a string representing a folder
&apos;&apos;&apos;	Returns:
&apos;&apos;&apos;		True if FolderName is a valid folder name and it exists
&apos;&apos;&apos;		False otherwise including when FolderName is a file
&apos;&apos;&apos;	Example:
&apos;&apos;&apos;		FSO.FileNaming = &quot;SYS&quot;
&apos;&apos;&apos;		If FSO.FolderExists(&quot;C:\&quot;) Then ...

Dim bExists As Boolean			&apos;	Return value
Dim oSfa As Object				&apos;	com.sun.star.ucb.SimpleFileAccess

Const cstThisSub = &quot;FileSystem.FolderExists&quot;
Const cstSubArgs = &quot;FolderName&quot;

	If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
	bExists = False

Check:
	If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
		If Not SF_Utils._ValidateFile(FolderName, &quot;FolderName&quot;) Then GoTo Finally
	End If
	FolderName = SF_FileSystem._ConvertToUrl(FolderName)

Try:
	Set oSfa = SF_Utils._GetUnoService(&quot;FileAccess&quot;)
	bExists = oSfa.isFolder(FolderName)

Finally:
	FolderExists = bExists
	SF_Utils._ExitFunction(cstThisSub)
	Exit Function
Catch:
	GoTo Finally
End Function    &apos;   ScriptForge.SF_FileSystem.FolderExists

REM -----------------------------------------------------------------------------
Public Function GetBaseName(Optional ByVal FileName As Variant) As String
&apos;&apos;&apos;	Returns the BaseName part of the last component of a File- or FolderName, without its extension
&apos;&apos;&apos;	The method does not check for the existence of the specified file or folder
&apos;&apos;&apos;	Args:
&apos;&apos;&apos;		FileName: Path and file name
&apos;&apos;&apos;	Returns:
&apos;&apos;&apos;		The BaseName of the given argument in native operating system format. May be empty
&apos;&apos;&apos;	Example:
&apos;&apos;&apos;		Dim a As String
&apos;&apos;&apos;		    FSO.FileNaming = &quot;SYS&quot;
&apos;&apos;&apos;			a = FSO.GetBaseName(&quot;C:\Windows\Notepad.exe&quot;) returns Notepad

Dim sBase As String				&apos;	Return value
Dim sExt As String				&apos;	Extension
Dim sName As String				&apos;	Last component of FileName
Dim vName As Variant			&apos;	Array of trunks of sName
Const cstThisSub = &quot;FileSystem.GetBaseName&quot;
Const cstSubArgs = &quot;FileName&quot;

	If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
	sBase = &quot;&quot;

Check:
	If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
		If Not SF_Utils._ValidateFile(FileName, &quot;FileName&quot;) Then GoTo Finally
	End If

Try:
	sName = SF_FileSystem.GetName(FileName)
	If Len(sName) &gt; 0 Then
		If InStr(sName, &quot;.&quot;) &gt; 0 Then
			vName = Split(sName, &quot;.&quot;)
			sExt = vName(UBound(vName))
			sBase = Left(sName, Len(sName) - Len(sExt) - 1)
		Else
			sBase = sName
		End If
	End If

Finally:
	GetBaseName = sBase
	SF_Utils._ExitFunction(cstThisSub)
	Exit Function
Catch:
	GoTo Finally
End Function	&apos;	ScriptForge.SF_FileSystem.GetBaseName

REM -----------------------------------------------------------------------------
Public Function GetExtension(Optional ByVal FileName As Variant) As String
&apos;&apos;&apos;	Returns the extension part of a File- or FolderName, without the dot (.).
&apos;&apos;&apos;	The method does not check for the existence of the specified file or folder
&apos;&apos;&apos;	Args:
&apos;&apos;&apos;		FileName: Path and file name
&apos;&apos;&apos;	Returns:
&apos;&apos;&apos;		The extension without a leading dot. May be empty
&apos;&apos;&apos;	Example:
&apos;&apos;&apos;		Dim a As String
&apos;&apos;&apos;		    FSO.FileNaming = &quot;SYS&quot;
&apos;&apos;&apos;			a = FSO.GetExtension(&quot;C:\Windows\Notepad.exe&quot;) returns exe

Dim sExt As String				&apos;	Return value
Dim sName As String				&apos;	Last component of FileName
Dim vName As Variant			&apos;	Array of trunks of sName
Const cstThisSub = &quot;FileSystem.GetExtension&quot;
Const cstSubArgs = &quot;FileName&quot;

	If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
	sExt = &quot;&quot;

Check:
	If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
		If Not SF_Utils._ValidateFile(FileName, &quot;FileName&quot;) Then GoTo Finally
	End If

Try:
	sName = SF_FileSystem.GetName(FileName)
	If Len(sName) &gt; 0 And InStr(sName, &quot;.&quot;) &gt; 0 Then
		vName = Split(sName, &quot;.&quot;)
		sExt = vName(UBound(vName))
	End If

Finally:
	GetExtension = sExt
	SF_Utils._ExitFunction(cstThisSub)
	Exit Function
Catch:
	GoTo Finally
End Function	&apos;	ScriptForge.SF_FileSystem.GetExtension

REM -----------------------------------------------------------------------------
Public Function GetFileLen(Optional ByVal FileName As Variant) As Currency
&apos;&apos;&apos;	Return file size in bytes with four decimals &apos;&apos;&apos;
&apos;&apos;&apos;	Args:
&apos;&apos;&apos;		FileName: a string representing a file
&apos;&apos;&apos;	Returns:
&apos;&apos;&apos;		File size if FileName exists
&apos;&apos;&apos;	Exceptions:
&apos;&apos;&apos;		UNKNOWNFILEERROR	The file does not exist of is a folder
&apos;&apos;&apos;	Example:
&apos;&apos;&apos;		Print SF_FileSystem.GetFileLen(&quot;C:\pagefile.sys&quot;)

Dim curSize As Currency			&apos;	Return value
Const cstPyHelper = &quot;$&quot; &amp; &quot;_SF_FileSystem__GetFilelen&quot;
Const cstThisSub = &quot;FileSystem.GetFileLen&quot;
Const cstSubArgs = &quot;FileName&quot;

	If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
	curSize = 0

Check:
	If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
		If Not SF_Utils._ValidateFile(FileName, &quot;FileName&quot;) Then GoTo Finally
	End If

Try:
	If SF_FileSystem.FileExists(FileName) Then
		With ScriptForge.SF_Session
			curSize = .ExecutePythonScript(.SCRIPTISSHARED, _SF_.PythonHelper &amp; cstPyHelper _
							, _ConvertFromUrl(FileName))
		End With
	Else
		GoTo CatchNotExists
	End If

Finally:
	GetFileLen = curSize
	SF_Utils._ExitFunction(cstThisSub)
	Exit Function
Catch:
	GoTo Finally
CatchNotExists:
	SF_Exception.RaiseFatal(UNKNOWNFILEERROR, &quot;FileName&quot;, FileName)
	GoTo Finally
End Function    &apos;   ScriptForge.SF_FileSystem.GetFileLen

REM -----------------------------------------------------------------------------
Public Function GetFileModified(Optional ByVal FileName As Variant) As Variant
&apos;&apos;&apos;	Returns the last modified date for the given file
&apos;&apos;&apos;	Args:
&apos;&apos;&apos;		FileName: a string representing an existing file
&apos;&apos;&apos;	Returns:
&apos;&apos;&apos;		The modification date and time as a Basic Date
&apos;&apos;&apos;	Exceptions:
&apos;&apos;&apos;		UNKNOWNFILEERROR	The file does not exist of is a folder
&apos;&apos;&apos;	Example:
&apos;&apos;&apos;		Dim a As Date
&apos;&apos;&apos;			FSO.FileNaming = &quot;SYS&quot;
&apos;&apos;&apos;			a = FSO.GetFileModified(&quot;C:\Temp\myDoc.odt&quot;)

Dim dModified As Date			&apos;	Return value
Dim oModified As New com.sun.star.util.DateTime
Dim oSfa As Object				&apos;	com.sun.star.ucb.SimpleFileAccess

Const cstThisSub = &quot;FileSystem.GetFileModified&quot;
Const cstSubArgs = &quot;FileName&quot;

	If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
	dModified = 0

Check:
	If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
		If Not SF_Utils._ValidateFile(FileName, &quot;FileName&quot;) Then GoTo Finally
	End If

Try:
	Set oSfa = SF_Utils._GetUnoService(&quot;FileAccess&quot;)
	If SF_FileSystem.FileExists(FileName) Then
		FileName = SF_FileSystem._ConvertToUrl(FileName)
		Set oModified = oSfa.getDateTimeModified(FileName)
		dModified = CDateFromUnoDateTime(oModified)
	Else
		GoTo CatchNotExists
	End If

Finally:
	GetFileModified = dModified
	SF_Utils._ExitFunction(cstThisSub)
	Exit Function
Catch:
	GoTo Finally
CatchNotExists:
	SF_Exception.RaiseFatal(UNKNOWNFILEERROR, &quot;FileName&quot;, FileName)
	GoTo Finally
End Function    &apos;   ScriptForge.SF_FileSystem.GetFileModified

REM -----------------------------------------------------------------------------
Public Function GetName(Optional ByVal FileName As Variant) As String
&apos;&apos;&apos;	Returns the last component of a File- or FolderName
&apos;&apos;&apos;	The method does not check for the existence of the specified file or folder
&apos;&apos;&apos;	Args:
&apos;&apos;&apos;		FileName: Path and file name
&apos;&apos;&apos;	Returns:
&apos;&apos;&apos;		The last component of the full file name in native operating system format
&apos;&apos;&apos;	Example:
&apos;&apos;&apos;		Dim a As String
&apos;&apos;&apos;		    FSO.FileNaming = &quot;SYS&quot;
&apos;&apos;&apos;			a = FSO.GetName(&quot;C:\Windows\Notepad.exe&quot;) returns Notepad.exe

Dim sName As String				&apos;	Return value
Dim vFile As Variant			&apos;	Array of components
Const cstThisSub = &quot;FileSystem.GetName&quot;
Const cstSubArgs = &quot;FileName&quot;

	If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
	sName = &quot;&quot;

Check:
	If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
		If Not SF_Utils._ValidateFile(FileName, &quot;FileName&quot;) Then GoTo Finally
	End If
	FileName = SF_FileSystem._ConvertToUrl(FileName)

Try:
	If Len(FileName) &gt; 0 Then
		If Right(FileName, 1) = &quot;/&quot; Then FileName = Left(FileName, Len(FileName) - 1)
		vFile = Split(FileName, &quot;/&quot;)
		sName = ConvertFromUrl(vFile(UBound(vFile)))	&apos;	Always in SYS format
	End If

Finally:
	GetName = sName
	SF_Utils._ExitFunction(cstThisSub)
	Exit Function
Catch:
	GoTo Finally
End Function	&apos;	ScriptForge.SF_FileSystem.GetName

REM -----------------------------------------------------------------------------
Public Function GetParentFolderName(Optional ByVal FileName As Variant) As String
&apos;&apos;&apos;	Returns a string containing the name of the parent folder of the last component in a specified File- or FolderName
&apos;&apos;&apos;	The method does not check for the existence of the specified file or folder
&apos;&apos;&apos;	Args:
&apos;&apos;&apos;		FileName: Path and file name
&apos;&apos;&apos;	Returns:
&apos;&apos;&apos;		A FolderName including its final path separator
&apos;&apos;&apos;	Example:
&apos;&apos;&apos;		Dim a As String
&apos;&apos;&apos;		    FSO.FileNaming = &quot;SYS&quot;
&apos;&apos;&apos;			a = FSO.GetParentFolderName(&quot;C:\Windows\Notepad.exe&quot;) returns C:\Windows\

Dim sFolder As String			&apos;	Return value
Dim sName As String				&apos;	Last component of FileName
Dim vFile As Variant			&apos;	Array of file components
Const cstThisSub = &quot;FileSystem.GetParentFolderName&quot;
Const cstSubArgs = &quot;FileName&quot;

	If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
	sFolder = &quot;&quot;

Check:
	If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
		If Not SF_Utils._ValidateFile(FileName, &quot;FileName&quot;) Then GoTo Finally
	End If
	FileName = SF_FileSystem._ConvertToUrl(FileName)

Try:
	If Right(FileName, 1) = &quot;/&quot; Then FileName = Left(FileName, Len(FileName) - 1)
	vFile = Split(FileName, &quot;/&quot;)
	If UBound(vFile) &gt;= 0 Then vFile(UBound(vFile)) = &quot;&quot;
	sFolder = Join(vFile, &quot;/&quot;)
	If sFolder = &quot;&quot; Or Right(sFolder, 1) &lt;&gt; &quot;/&quot; Then sFolder = sFolder &amp; &quot;/&quot;

Finally:
	GetParentFolderName = SF_FileSystem._ConvertFromUrl(sFolder)
	SF_Utils._ExitFunction(cstThisSub)
	Exit Function
Catch:
	GoTo Finally
End Function	&apos;	ScriptForge.SF_FileSystem.GetParentFolderName

REM -----------------------------------------------------------------------------
Public Function GetProperty(Optional ByVal PropertyName As Variant) As Variant
&apos;&apos;&apos;	Return the actual value of the given property
&apos;&apos;&apos;	Args:
&apos;&apos;&apos;		PropertyName: the name of the property as a string
&apos;&apos;&apos;	Returns:
&apos;&apos;&apos;		The actual value of the property
&apos;&apos;&apos;	Exceptions
&apos;&apos;&apos;		ARGUMENTERROR		The property does not exist

Const cstThisSub = &quot;FileSystem.GetProperty&quot;
Const cstSubArgs = &quot;PropertyName&quot;

	If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
	GetProperty = Null

Check:
	If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
		If Not SF_Utils._Validate(PropertyName, &quot;PropertyName&quot;, V_STRING, Properties()) Then GoTo Catch
	End If

Try:
	Select Case UCase(PropertyName)
		Case UCase(&quot;ConfigFolder&quot;)			:	GetProperty = ConfigFolder
		Case UCase(&quot;ExtensionsFolder&quot;)		:	GetProperty = ExtensionsFolder
		Case UCase(&quot;FileNaming&quot;)			:	GetProperty = FileNaming
		Case UCase(&quot;HomeFolder&quot;)			:	GetProperty = HomeFolder
		Case UCase(&quot;InstallFolder&quot;)			:	GetProperty = InstallFolder
		Case UCase(&quot;TemplatesFolder&quot;)		:	GetProperty = TemplatesFolder
		Case UCase(&quot;TemporaryFolder&quot;)		:	GetProperty = TemporaryFolder
		Case UCase(&quot;UserTemplatesFolder&quot;)	:	GetProperty = UserTemplatesFolder
		Case Else
	End Select

Finally:
	SF_Utils._ExitFunction(cstThisSub)
	Exit Function
Catch:
	GoTo Finally
End Function	&apos;	ScriptForge.SF_FileSystem.GetProperty

REM -----------------------------------------------------------------------------
Public Function GetTempName() As String
&apos;&apos;&apos;	Returns a randomly generated temporary file name that is useful for performing
&apos;&apos;&apos;	operations that require a temporary file : the method does not create any file
&apos;&apos;&apos;	Args:
&apos;&apos;&apos;	Returns:
&apos;&apos;&apos;		A FileName as a String that can be used f.i. with CreateTextFile()
&apos;&apos;&apos;		The FileName does not have any suffix
&apos;&apos;&apos;	Example:
&apos;&apos;&apos;		Dim a As String
&apos;&apos;&apos;			FSO.FileNaming = &quot;SYS&quot;
&apos;&apos;&apos;			a = FSO.GetTempName() &amp; &quot;.txt&quot;

Dim sFile As String				&apos;	Return value
Dim sTempDir As String			&apos;	The path to a temporary folder
Dim lRandom As Long				&apos;	Random integer

Const cstThisSub = &quot;FileSystem.GetTempName&quot;
Const cstSubArgs = &quot;&quot;

	If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
	sFile = &quot;&quot;

Check:
	SF_Utils._EnterFunction(cstThisSub, cstSubArgs)

Try:
	lRandom = SF_Session.ExecuteCalcFunction(&quot;RANDBETWEEN&quot;, 1, 999999)
	sFile = SF_FileSystem.TemporaryFolder &amp; &quot;SF_&quot; &amp; Right(&quot;000000&quot; &amp; lRandom, 6)

Finally:
	GetTempName = SF_FileSystem._ConvertFromUrl(sFile)
	SF_Utils._ExitFunction(cstThisSub)
	Exit Function
Catch:
	GoTo Finally
End Function    &apos;   ScriptForge.SF_FileSystem.GetTempName

REM -----------------------------------------------------------------------------
Public Function HashFile(Optional ByVal FileName As Variant _
							, Optional ByVal Algorithm As Variant _
							) As String
&apos;&apos;&apos;	Return an hexadecimal string representing a checksum of the given file
&apos;&apos;&apos;	Next algorithms are supported: MD5, SHA1, SHA224, SHA256, SHA384 and SHA512
&apos;&apos;&apos;	Args:
&apos;&apos;&apos;		FileName: a string representing a file
&apos;&apos;&apos;		Algorithm: The hashing algorithm to use
&apos;&apos;&apos;	Returns:
&apos;&apos;&apos;		The requested checksum as a string. Hexadecimal digits are lower-cased
&apos;&apos;&apos;		A zero-length string when an error occurred
&apos;&apos;&apos;	Exceptions:
&apos;&apos;&apos;		UNKNOWNFILEERROR	The file does not exist of is a folder
&apos;&apos;&apos;	Example:
&apos;&apos;&apos;		Print SF_FileSystem.HashFile(&quot;C:\pagefile.sys&quot;, &quot;MD5&quot;)

Dim sHash As String				&apos;	Return value
Const cstPyHelper = &quot;$&quot; &amp; &quot;_SF_FileSystem__HashFile&quot;
Const cstThisSub = &quot;FileSystem.HashFile&quot;
Const cstSubArgs = &quot;FileName, Algorithm=&quot;&quot;MD5&quot;&quot;|&quot;&quot;SHA1&quot;&quot;|&quot;&quot;SHA224&quot;&quot;|&quot;&quot;SHA256&quot;&quot;|&quot;&quot;SHA384&quot;&quot;|&quot;&quot;SHA512&quot;&quot;&quot;

	If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
	sHash = &quot;&quot;

Check:
	If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
		If Not SF_Utils._ValidateFile(FileName, &quot;FileName&quot;) Then GoTo Finally
		If Not SF_Utils._Validate(Algorithm, &quot;Algorithm&quot;, V_STRING _
					, Array(&quot;MD5&quot;, &quot;SHA1&quot;, &quot;SHA224&quot;, &quot;SHA256&quot;, &quot;SHA384&quot;, &quot;SHA512&quot;)) Then GoTo Finally
	End If

Try:
	If SF_FileSystem.FileExists(FileName) Then
		With ScriptForge.SF_Session
			sHash = .ExecutePythonScript(.SCRIPTISSHARED, _SF_.PythonHelper &amp; cstPyHelper _
							, _ConvertFromUrl(FileName), LCase(Algorithm))
		End With
	Else
		GoTo CatchNotExists
	End If

Finally:
	HashFile = sHash
	SF_Utils._ExitFunction(cstThisSub)
	Exit Function
Catch:
	GoTo Finally
CatchNotExists:
	SF_Exception.RaiseFatal(UNKNOWNFILEERROR, &quot;FileName&quot;, FileName)
	GoTo Finally
End Function    &apos;   ScriptForge.SF_FileSystem.HashFile

REM -----------------------------------------------------------------------------
Public Function Methods() As Variant
&apos;&apos;&apos;	Return the list or methods of the FileSystem service as an array

	Methods = Array(&quot;BuildPath&quot; _
					, &quot;CompareFiles&quot; _
					, &quot;CopyFile&quot; _
					, &quot;CopyFolder&quot; _
					, &quot;CreateFolder&quot; _
					, &quot;CreateTextFile&quot; _
					, &quot;DeleteFile&quot; _
					, &quot;DeleteFolder&quot; _
					, &quot;ExtensionFolder&quot; _
					, &quot;FileExists&quot; _
					, &quot;Files&quot; _
					, &quot;FolderExists&quot; _
					, &quot;GetBaseName&quot; _
					, &quot;GetExtension&quot; _
					, &quot;GetFileLen&quot; _
					, &quot;GetFileModified&quot; _
					, &quot;GetName&quot; _
					, &quot;GetParentFolderName&quot; _
					, &quot;GetTempName&quot; _
					, &quot;HashFile&quot; _
					, &quot;MoveFile&quot; _
					, &quot;MoveFolder&quot; _
					, &quot;OpenTextFile&quot; _
					, &quot;PickFile&quot; _
					, &quot;PickFolder&quot; _
					, &quot;SubFolders&quot; _
					)

End Function	&apos;	ScriptForge.SF_FileSystem.Methods

REM -----------------------------------------------------------------------------
Public Function MoveFile(Optional ByVal Source As Variant _
							, Optional ByVal Destination As Variant _
							) As Boolean
&apos;&apos;&apos;	Moves one or more files from one location to another
&apos;&apos;&apos;	Args:
&apos;&apos;&apos;		Source: FileName or NamePattern which can include wildcard characters, for one or more files to be moved
&apos;&apos;&apos;		Destination:	FileName where the single Source file is to be moved
&apos;&apos;&apos;							If Source and Destination have the same parent folder MoveFile amounts to renaming the Source
&apos;&apos;&apos;					or	FolderName where the multiple files from Source are to be moved
&apos;&apos;&apos;							If FolderName does not exist, it is created
&apos;&apos;&apos;					Anyway, wildcard characters are not allowed in Destination
&apos;&apos;&apos;	Returns:
&apos;&apos;&apos;		True if at least one file has been moved
&apos;&apos;&apos;		False if an error occurred
&apos;&apos;&apos;			An error also occurs if a source using wildcard characters doesn&apos;t match any files.
&apos;&apos;&apos;			The method stops on the first error it encounters
&apos;&apos;&apos;			No attempt is made to roll back or undo any changes made before an error occurs
&apos;&apos;&apos;	Exceptions:
&apos;&apos;&apos;		UNKNOWNFILEERROR			Source does not exist
&apos;&apos;&apos;		UNKNOWNFOLDERERROR			Source folder or Destination folder does not exist
&apos;&apos;&apos;		NOFILEMATCHERROR		No file matches Source containing wildcards
&apos;&apos;&apos;		NOTAFOLDERERROR				Destination is a file, not a folder
&apos;&apos;&apos;		NOTAFILEERROR				Destination is a folder, not a file
&apos;&apos;&apos;		OVERWRITEERROR				Destination can not be overwritten
&apos;&apos;&apos;	Example:
&apos;&apos;&apos;		FSO.FileNaming = &quot;SYS&quot;
&apos;&apos;&apos;		FSO.MoveFile(&quot;C:\Temp1\*.*&quot;, &quot;C:\Temp2\&quot;)		&apos;	Only files are moved, subfolders are not

Dim bMove As Boolean			&apos;	Return value

Const cstThisSub = &quot;FileSystem.MoveFile&quot;
Const cstSubArgs = &quot;Source, Destination&quot;

	If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
	bMove = False

Check: 
	If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
		If Not SF_Utils._ValidateFile(Source, &quot;Source&quot;, True) Then GoTo Finally
		If Not SF_Utils._ValidateFile(Destination, &quot;Destination&quot;, False) Then GoTo Finally
	End If

Try:
	bMove = SF_FileSystem._CopyMove(&quot;MoveFile&quot;, Source, Destination, False)

Finally:
	MoveFile = bMove
	SF_Utils._ExitFunction(cstThisSub)
	Exit Function
Catch:
	GoTo Finally
End Function    &apos;   ScriptForge.SF_FileSystem.MoveFile

REM -----------------------------------------------------------------------------
Public Function MoveFolder(Optional ByVal Source As Variant _
							, Optional ByVal Destination As Variant _
							) As Boolean
&apos;&apos;&apos;	Moves one or more folders from one location to another
&apos;&apos;&apos;	Args:
&apos;&apos;&apos;		Source: FolderName or NamePattern which can include wildcard characters, for one or more folders to be moved
&apos;&apos;&apos;		Destination:	FolderName where the single Source folder is to be moved
&apos;&apos;&apos;							FolderName must not exist
&apos;&apos;&apos;					or	FolderName where the multiple folders from Source are to be moved
&apos;&apos;&apos;							If FolderName does not exist, it is created
&apos;&apos;&apos;					Anyway, wildcard characters are not allowed in Destination
&apos;&apos;&apos;	Returns:
&apos;&apos;&apos;		True if at least one folder has been moved
&apos;&apos;&apos;		False if an error occurred
&apos;&apos;&apos;			An error also occurs if a source using wildcard characters doesn&apos;t match any folders.
&apos;&apos;&apos;			The method stops on the first error it encounters
&apos;&apos;&apos;			No attempt is made to roll back or undo any changes made before an error occurs
&apos;&apos;&apos;	Exceptions:
&apos;&apos;&apos;		UNKNOWNFILEERROR			Source does not exist
&apos;&apos;&apos;		UNKNOWNFOLDERERROR			Source folder or Destination folder does not exist
&apos;&apos;&apos;		NOFILEMATCHERROR		No file matches Source containing wildcards
&apos;&apos;&apos;		NOTAFOLDERERROR				Destination is a file, not a folder
&apos;&apos;&apos;		OVERWRITEERROR				Destination can not be overwritten
&apos;&apos;&apos;	Example:
&apos;&apos;&apos;		FSO.FileNaming = &quot;SYS&quot;
&apos;&apos;&apos;		FSO.MoveFolder(&quot;C:\Temp1\*&quot;, &quot;C:\Temp2\&quot;)

Dim bMove As Boolean			&apos;	Return value

Const cstThisSub = &quot;FileSystem.MoveFolder&quot;
Const cstSubArgs = &quot;Source, Destination&quot;

	If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
	bMove = False

Check: 
	If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
		If Not SF_Utils._ValidateFile(Source, &quot;Source&quot;, True) Then GoTo Finally
		If Not SF_Utils._ValidateFile(Destination, &quot;Destination&quot;, False) Then GoTo Finally
	End If

Try:
	bMove = SF_FileSystem._CopyMove(&quot;MoveFolder&quot;, Source, Destination, False)

Finally:
	MoveFolder = bMove
	SF_Utils._ExitFunction(cstThisSub)
	Exit Function
Catch:
	GoTo Finally
End Function    &apos;   ScriptForge.SF_FileSystem.MoveFolder

REM -----------------------------------------------------------------------------
Public Function OpenTextFile(Optional ByVal FileName As Variant _
								, Optional ByVal IOMode As Variant _
								, Optional ByVal Create As Variant _
								, Optional ByVal Encoding As Variant _
								) As Object
&apos;&apos;&apos;	Opens a specified file and returns a TextStream object that can be used to read from, write to, or append to the file
&apos;&apos;&apos;	Args:
&apos;&apos;&apos;		FileName: Identifies the file to open
&apos;&apos;&apos;		IOMode: Indicates input/output mode. Can be one of three constants: ForReading, ForWriting, or ForAppending
&apos;&apos;&apos;		Create: Boolean value that indicates whether a new file can be created if the specified filename doesn&apos;t exist.
&apos;&apos;&apos;				The value is True if a new file and its parent folders may be created; False if they aren&apos;t created (default)
&apos;&apos;&apos;		Encoding: The character set that should be used
&apos;&apos;&apos;				Use one of the Names listed in https://www.iana.org/assignments/character-sets/character-sets.xhtml
&apos;&apos;&apos;				Note that LibreOffice does not implement all existing sets
&apos;&apos;&apos;				Default = UTF-8
&apos;&apos;&apos;	Returns:
&apos;&apos;&apos;		An instance of the SF_TextStream class representing the opened file or a Null object if an error occurred
&apos;&apos;&apos;		The method does not check if the file is really a text file
&apos;&apos;&apos;		It doesn&apos;t check either if the given encoding is implemented in LibreOffice nor if it is the right one
&apos;&apos;&apos;	Exceptions:
&apos;&apos;&apos;		UNKNOWNFILEERROR		File does not exist
&apos;&apos;&apos;	Example:
&apos;&apos;&apos;		Dim myFile As Object
&apos;&apos;&apos;		    FSO.FileNaming = &quot;SYS&quot;
&apos;&apos;&apos;			Set myFile = FSO.OpenTextFile(&quot;C:\Temp\ThisFile.txt&quot;, FSO.ForReading)
&apos;&apos;&apos;			If Not IsNull(myFile) Then	&apos; ... Go ahead with reading text lines

Dim oTextStream As Object		&apos;	Return value
Dim bExists As Boolean			&apos;	File to open does exist
Const cstThisSub = &quot;FileSystem.OpenTextFile&quot;
Const cstSubArgs = &quot;FileName, [IOMode=1], [Create=False], [Encoding=&quot;&quot;UTF-8&quot;&quot;]&quot;

	If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
	Set oTextStream = Nothing

Check:
	With SF_FileSystem
		If IsMissing(IOMode) Or IsEmpty(IOMode) Then IOMode = ForReading
		If IsMissing(Create) Or IsEmpty(Create) Then Create = False
		If IsMissing(Encoding) Or IsEmpty(Encoding) Then Encoding = &quot;UTF-8&quot;
		If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
			If Not SF_Utils._ValidateFile(FileName, &quot;FileName&quot;) Then GoTo Finally
			If Not SF_Utils._Validate(IOMode, &quot;IOMode&quot;, V_NUMERIC _
					, Array(ForReading, ForWriting, ForAppending)) _
						Then GoTo Finally
			If Not SF_Utils._Validate(Create, &quot;Create&quot;, V_BOOLEAN) Then GoTo Finally
			If Not SF_Utils._Validate(Encoding, &quot;Encoding&quot;, V_STRING) Then GoTo Finally
		End If

		bExists = .FileExists(FileName)
		Select Case IOMode
			Case ForReading		:	If Not bExists Then GoTo CatchNotExists
			Case Else			:	If Not bExists And Not Create Then GoTo CatchNotExists
		End Select

		If IOMode = ForAppending And Not bExists Then IOMode = ForWriting
	End With

Try:
	&apos;	Create and initialize TextStream class instance
	Set oTextStream = New SF_TextStream
	With oTextStream
		.[Me] = oTextStream
		.[_Parent] = SF_FileSystem
		._FileName = SF_FileSystem._ConvertToUrl(FileName)
		._IOMode = IOMode
		._Encoding = Encoding
		._FileExists = bExists
		._Initialize()
	End With

Finally:
	Set OpenTextFile = oTextStream
	SF_Utils._ExitFunction(cstThisSub)
	Exit Function
Catch:
	GoTo Finally
CatchNotExists:
	SF_Exception.RaiseFatal(UNKNOWNFILEERROR, &quot;FileName&quot;, FileName)
	GoTo Finally
End Function	&apos;	ScriptForge.SF_FileSystem.OpenTextFile

REM -----------------------------------------------------------------------------
Public Function PickFile(Optional ByVal DefaultFile As Variant _
							, Optional ByVal Mode As Variant _
							, Optional ByVal Filter As Variant _
							) As String
&apos;&apos;&apos;	Returns the file selected with a FilePicker dialog box
&apos;&apos;&apos;	The mode, OPEN or SAVE, and the filter may be preset
&apos;&apos;&apos;	If mode = SAVE and the picked file exists, a warning message will be displayed
&apos;&apos;&apos;	Modified from Andrew Pitonyak&apos;s Base Macro Programming §10.4
&apos;&apos;&apos;	Args:
&apos;&apos;&apos;		DefaultFile:	Folder part: the FolderName from which to start. Default = the last selected folder
&apos;&apos;&apos;						File part: the default file to open or save
&apos;&apos;&apos;		Mode: &quot;OPEN&quot; (input file) or &quot;SAVE&quot; (output file)
&apos;&apos;&apos;		Filter: by default only files having the given suffix will be displayed. Default = all suffixes
&apos;&apos;&apos;			The filter combo box will contain the given SuffixFilter (if not &quot;*&quot;) and &quot;*.*&quot;
&apos;&apos;&apos;	Returns:
&apos;&apos;&apos;		The selected FileName in URL format or &quot;&quot; if the dialog was cancelled
&apos;&apos;&apos;	Example:
&apos;&apos;&apos;		FSO.FileNaming = &quot;SYS&quot;
&apos;&apos;&apos;		FSO.PickFile(&quot;C:\&quot;, &quot;OPEN&quot;, &quot;txt&quot;)		&apos; Only *.txt files are displayed

Dim oFileDialog As Object		&apos;	com.sun.star.ui.dialogs.FilePicker
Dim oFileAccess As object		&apos;	com.sun.star.ucb.SimpleFileAccess
Dim oPath As Object				&apos;	com.sun.star.util.PathSettings
Dim iAccept As Integer			&apos;	Result of dialog execution
Dim sInitPath As String			&apos;	Current working directory
Dim sBaseFile As String
Dim iMode As Integer			&apos;	Numeric alias for SelectMode
Dim sFile As String				&apos;	Return value

Const cstThisSub = &quot;FileSystem.PickFile&quot;
Const cstSubArgs = &quot;[DefaultFile=&quot;&quot;&quot;&quot;], [Mode=&quot;&quot;OPEN&quot;&quot;|&quot;&quot;SAVE&quot;&quot;],[Filter=&quot;&quot;&quot;&quot;]&quot;

	If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
	sFile = &quot;&quot;

Check:
	If IsMissing(DefaultFile) Or IsEmpty(DefaultFile) Then DefaultFile = &quot;&quot;
	If IsMissing(Mode) Or IsEmpty(Mode) Then Mode = &quot;OPEN&quot;
	If IsMissing(Filter) Or IsEmpty(Filter) Then Filter = &quot;&quot;
	If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
		If Not SF_Utils._ValidateFile(DefaultFile, &quot;DefaultFile&quot;, , True) Then GoTo Finally
		If Not SF_Utils._Validate(Mode, &quot;Mode&quot;, V_STRING, Array(&quot;OPEN&quot;, &quot;SAVE&quot;)) Then GoTo Finally
		If Not SF_Utils._Validate(Filter, &quot;Filter&quot;, V_STRING) Then GoTo Finally
	End If
	DefaultFile = SF_FileSystem._ConvertToUrl(DefaultFile)

Try:
	&apos; Derive numeric equivalent of the Mode argument: https://api.libreoffice.org/docs/idl/ref/TemplateDescription_8idl.html
	With com.sun.star.ui.dialogs.TemplateDescription
		If Mode = &quot;OPEN&quot; Then iMode = .FILEOPEN_SIMPLE Else iMode = .FILESAVE_AUTOEXTENSION
	End With

	&apos; Activate the filepicker dialog
	Set oFileDialog = SF_Utils._GetUNOService(&quot;FilePicker&quot;)
	With oFileDialog
		.Initialize(Array(iMode))

		&apos; Set filters
		If Len(Filter) &gt; 0 Then .appendFilter(&quot;*.&quot; &amp; Filter, &quot;*.&quot; &amp; Filter)		&apos; Twice: required by API
		.appendFilter(&quot;*.*&quot;, &quot;*.*&quot;)
		If Len(Filter) &gt; 0 Then .setCurrentFilter(&quot;*.&quot; &amp; Filter) Else .setCurrentFilter(&quot;*.*&quot;)

		&apos; Set initial folder
		If Len(DefaultFile) = 0 Then	&apos; TODO: SF_Session.WorkingFolder
			Set oPath = SF_Utils._GetUNOService(&quot;PathSettings&quot;)
			sInitPath = oPath.Work		&apos;	Probably My Documents
		Else
			sInitPath = SF_FileSystem._ParseUrl(ConvertToUrl(DefaultFile)).Path
		End If

		&apos; Set default values
		Set oFileAccess = SF_Utils._GetUNOService(&quot;FileAccess&quot;)
		If oFileAccess.exists(sInitPath) Then .SetDisplayDirectory(sInitPath)
		sBaseFile = SF_FileSystem.GetName(DefaultFile)
		.setDefaultName(sBaseFile)

		&apos; Get selected file
		iAccept = .Execute()
		If iAccept = com.sun.star.ui.dialogs.ExecutableDialogResults.OK Then sFile = .getSelectedFiles()(0)
	End With

Finally:
	PickFile = SF_FileSystem._ConvertFromUrl(sFile)
	SF_Utils._ExitFunction(cstThisSub)
	Exit Function
Catch:
	GoTo Finally
End Function    &apos;   ScriptForge.SF_FileSystem.PickFile

REM -----------------------------------------------------------------------------
Public Function PickFolder(Optional ByVal DefaultFolder As Variant _
							, Optional ByVal FreeText As Variant _
							) As String
&apos;&apos;&apos;	Display a FolderPicker dialog box
&apos;&apos;&apos;	Args:
&apos;&apos;&apos;		DefaultFolder: the FolderName from which to start. Default = the last selected folder
&apos;&apos;&apos;		FreeText: text to display in the dialog. Default = &quot;&quot;
&apos;&apos;&apos;	Returns:
&apos;&apos;&apos;		The selected FolderName in URL or operating system format
&apos;&apos;&apos;		The zero-length string if the dialog was cancelled
&apos;&apos;&apos;	Example:
&apos;&apos;&apos;		FSO.FileNaming = &quot;SYS&quot;
&apos;&apos;&apos;		FSO.PickFolder(&quot;C:\&quot;, &quot;Choose a folder or press Cancel&quot;)

Dim oFolderDialog As Object		&apos;	com.sun.star.ui.dialogs.FolderPicker
Dim iAccept As Integer			&apos;	Value returned by the dialog (OK, Cancel, ..)
Dim sFolder	As String			&apos;	Return value					&apos;	

Const cstThisSub = &quot;FileSystem.PickFolder&quot;
Const cstSubArgs = &quot;[DefaultFolder=&quot;&quot;&quot;&quot;], [FreeText=&quot;&quot;&quot;&quot;]&quot;

	If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
	sFolder = &quot;&quot;

Check:
	If IsMissing(DefaultFolder) Or IsEmpty(DefaultFolder) Then DefaultFolder = &quot;&quot;
	If IsMissing(FreeText) Or IsEmpty(FreeText) Then FreeText = &quot;&quot;
	If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
		If Not SF_Utils._ValidateFile(DefaultFolder, &quot;DefaultFolder&quot;, , True) Then GoTo Finally
		If Not SF_Utils._Validate(FreeText, &quot;FreeText&quot;, V_STRING) Then GoTo Finally
	End If
	DefaultFolder = SF_FileSystem._ConvertToUrl(DefaultFolder)

Try:
	Set oFolderDialog = SF_Utils._GetUNOService(&quot;FolderPicker&quot;)
	If Not IsNull(oFolderDialog) Then
		With oFolderDialog
			If Len(DefaultFolder) &gt; 0 Then .DisplayDirectory = ConvertToUrl(DefaultFolder)
			.Description = FreeText
			iAccept = .Execute()
			&apos; https://api.libreoffice.org/docs/idl/ref/ExecutableDialogResults_8idl.html
			If iAccept = com.sun.star.ui.dialogs.ExecutableDialogResults.OK Then
				.DisplayDirectory = .Directory	&apos;	Set the next default initial folder to the selected one
				sFolder = .Directory &amp; &quot;/&quot;
			End If
		End With
	End If

Finally:
	PickFolder = SF_FileSystem._ConvertFromUrl(sFolder)
	SF_Utils._ExitFunction(cstThisSub)
	Exit Function
Catch:
	GoTo Finally
End Function    &apos;   ScriptForge.SF_FileSystem.PickFolder

REM -----------------------------------------------------------------------------
Public Function Properties() As Variant
&apos;&apos;&apos;	Return the list or properties of the FileSystem module as an array

	Properties = Array( _
					&quot;ConfigFolder&quot; _
					, &quot;ExtensionsFolder&quot; _
					, &quot;FileNaming&quot; _
					, &quot;HomeFolder&quot; _
					, &quot;InstallFolder&quot; _
					, &quot;TemplatesFolder&quot; _
					, &quot;TemporaryFolder&quot; _
					, &quot;UserTemplatesFolder&quot; _
					)

End Function	&apos;	ScriptForge.SF_FileSystem.Properties

REM -----------------------------------------------------------------------------
Public Function SetProperty(Optional ByVal PropertyName As Variant _
								, Optional ByRef Value As Variant _
								) As Boolean
&apos;&apos;&apos;	Set a new value to the given property
&apos;&apos;&apos;	Args:
&apos;&apos;&apos;		PropertyName: the name of the property as a string
&apos;&apos;&apos;		Value: its new value
&apos;&apos;&apos;	Exceptions
&apos;&apos;&apos;		ARGUMENTERROR		The property does not exist

Const cstThisSub = &quot;FileSystem.SetProperty&quot;
Const cstSubArgs = &quot;PropertyName, Value&quot;

	If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
	SetProperty = False

Check:
	If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
		If Not SF_Utils._Validate(PropertyName, &quot;PropertyName&quot;, V_STRING, Properties()) Then GoTo Catch
	End If

Try:
	Select Case UCase(PropertyName)
		Case UCase(&quot;FileNaming&quot;)		:	FileNaming = Value	
		Case Else
	End Select

Finally:
	SF_Utils._ExitFunction(cstThisSub)
	Exit Function
Catch:
	GoTo Finally
End Function	&apos;	ScriptForge.SF_FileSystem.SetProperty

REM -----------------------------------------------------------------------------
Public Function SubFolders(Optional ByVal FolderName As Variant _
								, Optional ByVal Filter As Variant _
								) As Variant
&apos;&apos;&apos;	Return an array of the FolderNames stored in the given folder. The folder must exist
&apos;&apos;&apos;	Args:
&apos;&apos;&apos;		FolderName: the folder to explore
&apos;&apos;&apos;		Filter: contains wildcards (&quot;?&quot; and &quot;*&quot;) to limit the list to the relevant folders (default = &quot;&quot;)
&apos;&apos;&apos;	Returns:
&apos;&apos;&apos;		An array of strings, each entry is the FolderName of an existing folder
&apos;&apos;&apos;	Exceptions:
&apos;&apos;&apos;		UNKNOWNFOLDERERROR		Folder does not exist
&apos;&apos;&apos;		NOTAFOLDERERROR			FolderName is a file, not a folder
&apos;&apos;&apos;	Example:
&apos;&apos;&apos;		Dim a As Variant
&apos;&apos;&apos;			FSO.FileNaming = &quot;SYS&quot;
&apos;&apos;&apos;			a = FSO.SubFolders(&quot;C:\Windows\&quot;)

Dim vSubFolders As Variant		&apos;	Return value
Dim oSfa As Object				&apos;	com.sun.star.ucb.SimpleFileAccess
Dim sFolderName As String		&apos;	URL lias for FolderName
Dim sFolder As String			&apos;	Single folder
Dim i As Long

Const cstThisSub = &quot;FileSystem.SubFolders&quot;
Const cstSubArgs = &quot;FolderName, [Filter=&quot;&quot;&quot;&quot;]&quot;

	If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
	vSubFolders = Array()

Check:
	If IsMissing(Filter) Or IsEmpty(Filter) Then Filter = &quot;&quot;
	If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
		If Not SF_Utils._ValidateFile(FolderName, &quot;FolderName&quot;) Then GoTo Finally
		If Not SF_Utils._Validate(Filter, &quot;Filter&quot;, V_STRING) Then GoTo Finally
	End If
	sFolderName = SF_FileSystem._ConvertToUrl(FolderName)
	If SF_FileSystem.FileExists(FolderName) Then GoTo CatchFile				&apos; Must not be a file
	If Not SF_FileSystem.FolderExists(FolderName) Then GoTo CatchFolder		&apos; Folder must exist

Try:
	&apos;	Get SubFolders
	Set oSfa = SF_Utils._GetUnoService(&quot;FileAccess&quot;)
	vSubFolders = oSfa.getFolderContents(sFolderName, True)
	&apos;	List includes files; remove them or adjust notations of folders
	For i = 0 To UBound(vSubFolders)
		sFolder = SF_FileSystem._ConvertFromUrl(vSubFolders(i) &amp; &quot;/&quot;)
		If SF_FileSystem.FileExists(sFolder) Then vSubFolders(i) = &quot;&quot; Else vSubFolders(i) = sFolder
		&apos;	Reduce list to those passing the filter
		If Len(Filter) &gt; 0 And Len(vSubFolders(i)) &gt; 0 Then
			sFolder = SF_FileSystem.GetName(vSubFolders(i))
			If Not SF_String.IsLike(sFolder, Filter) Then vSubFolders(i) = &quot;&quot;
		End If
	Next i
	vSubFolders = SF_Array.TrimArray(vSubFolders)

Finally:
	SubFolders = vSubFolders
	SF_Utils._ExitFunction(cstThisSub)
	Exit Function
Catch:
	GoTo Finally
CatchFile:
	SF_Exception.RaiseFatal(NOTAFOLDERERROR, &quot;FolderName&quot;, FolderName)
	GoTo Finally
CatchFolder:
	SF_Exception.RaiseFatal(UNKNOWNFOLDERERROR, &quot;FolderName&quot;, FolderName)
	GoTo Finally
End Function    &apos;   ScriptForge.SF_FileSystem.SubFolders

REM =========================================================== PRIVATE FUNCTIONS

REM -----------------------------------------------------------------------------
Private Function _ConvertFromUrl(psFile) As String
&apos;&apos;&apos;	Execute the builtin ConvertFromUrl function only when relevant
&apos;&apos;&apos;		i.e. when FileNaming (how arguments and return values are provided) = &quot;SYS&quot;
&apos;&apos;&apos;	Called at the bottom of methods returning file names
&apos;&apos;&apos;	Remark: psFile might contain wildcards

Const cstQuestion = &quot;$QUESTION$&quot;, cstStar = &quot;$STAR$&quot;	&apos;	Special tokens to replace wildcards

	If SF_FileSystem.FileNaming = &quot;SYS&quot; Then
		_ConvertFromUrl = Replace(Replace( _
							ConvertFromUrl(Replace(Replace(psFile, &quot;?&quot;, cstQuestion), &quot;*&quot;, cstStar)) _
							, cstQuestion, &quot;?&quot;), cstStar, &quot;*&quot;)
	Else
		_ConvertFromUrl = psFile
	End If

End Function	&apos;	ScriptForge.FileSystem._ConvertFromUrl

REM -----------------------------------------------------------------------------
Private Function _ConvertToUrl(psFile) As String
&apos;&apos;&apos;	Execute the builtin ConvertToUrl function only when relevant
&apos;&apos;&apos;		i.e. when FileNaming (how arguments and return values are provided) = &quot;SYS&quot;
&apos;&apos;&apos;	Called at the top of methods receiving file names as arguments
&apos;&apos;&apos;	Remark: psFile might contain wildcards

	If SF_FileSystem.FileNaming = &quot;URL&quot; Then
		_ConvertToUrl = psFile
	Else
		&apos;	ConvertToUrl encodes &quot;?&quot;
		_ConvertToUrl = Replace(ConvertToUrl(psFile), &quot;%3F&quot;, &quot;?&quot;)
	End If

End Function	&apos;	ScriptForge.FileSystem._ConvertToUrl

REM -----------------------------------------------------------------------------
Private Function _CopyMove(psMethod As String _
								, psSource As String _
								, psDestination As String _
								, pbOverWrite As Boolean _
								) As Boolean
&apos;&apos;&apos;	Checks the arguments and executes the given method
&apos;&apos;&apos;	Args:
&apos;&apos;&apos;		psMethod: CopyFile/CopyFolder or MoveFile/MoveFolder
&apos;&apos;&apos;		psSource: Either File/FolderName
&apos;&apos;&apos;					or NamePattern which can include wildcard characters, for one or more files/folders to be copied
&apos;&apos;&apos;		psDestination: FileName  or FolderName for copy/move of a single file/folder
&apos;&apos;&apos;						Otherwise a destination FolderName. If it does not exist, it is created
&apos;&apos;&apos;		pbOverWrite: If True, files/folders may be overwritten
&apos;&apos;&apos;						Must be False for Move operations
&apos;&apos;&apos;	Next checks are done:
&apos;&apos;&apos;		With wildcards (multiple files/folders):
&apos;&apos;&apos;			- Parent folder of source must exist
&apos;&apos;&apos;			- Destination must not be a file
&apos;&apos;&apos;			- Parent folder of Destination must exist
&apos;&apos;&apos;			- If the Destination folder does not exist a new folder is created,
&apos;&apos;&apos;			- At least one file matches the wildcards expression
&apos;&apos;&apos;			- Destination files/folder must not exist if pbOverWrite = False
&apos;&apos;&apos;			- Destination files/folders must not have the read-only attribute set
&apos;&apos;&apos;			- Destination files must not be folders, destination folders must not be files
&apos;&apos;&apos;		Without wildcards (single file/folder):
&apos;&apos;&apos;			- Source file/folder must exist and be a file/folder
&apos;&apos;&apos;			- Parent folder of Destination must exist
&apos;&apos;&apos;			- Destination must not be an existing folder/file
&apos;&apos;&apos;			- Destination file/folder must not exist if pbOverWrite = False
&apos;&apos;&apos;			- Destination file must not have the read-only attribute set

Dim bCopyMove As Boolean		&apos;	Return value
Dim bCopy As Boolean			&apos;	True if Copy, False if Move
Dim bFile As Boolean			&apos;	True if File, False if Folder
Dim oSfa As Object				&apos;	com.sun.star.ucb.SimpleFileAccess
Dim bWildCards As Boolean		&apos;	True if wildcards found in Source
Dim bCreateFolder As Boolean	&apos;	True when the destination folder should be created
Dim bDestExists As Boolean		&apos;	True if destination exists
Dim sSourceUrl As String		&apos;	Alias for Source
Dim sDestinationUrl As String	&apos;	Alias for Destination
Dim sDestinationFile As String	&apos;	Destination FileName
Dim sParentFolder As String		&apos;	Parent folder of Source
Dim vFiles As Variant			&apos;	Array of candidates for copy/move
Dim sFile As String				&apos;	Single file/folder
Dim sName As String				&apos;	Name (last component) of file
Dim i As Long

	&apos;	Error handling left to calling routine
	bCopyMove = False
	bCopy = ( Left(psMethod, 4) = &quot;Copy&quot; )
	bFile = ( Right(psMethod, 4) = &quot;File&quot; )
	bWildCards = ( InStr(psSource, &quot;*&quot;) + InStr(psSource, &quot;?&quot;) + InStr(psSource, &quot;%3F&quot;) &gt; 0 )	&apos;ConvertToUrl() converts sometimes &quot;?&quot; to &quot;%3F&quot;
	bDestExists = False

	With SF_FileSystem

Check:
		If bWildCards Then
			sParentFolder = .GetParentFolderName(psSource)
			If Not .FolderExists(sParentFolder) Then GoTo CatchNoMatch
			If .FileExists(psDestination) Then GoTo CatchFileNotFolder
			If Not .FolderExists(.GetParentFolderName(psDestination)) Then GoTo CatchDestFolderNotExists
			bCreateFolder = Not .FolderExists(psDestination)
		Else
			Select Case bFile
				Case True 	&apos; File
					If Not .FileExists(psSource) Then GoTo CatchFileNotExists
					If Not .FolderExists(.GetParentFolderName(psDestination)) Then GoTo CatchSourceFolderNotExists
					If .FolderExists(psDestination) Then GoTo CatchFolderNotFile
					bDestExists = .FileExists(psDestination)
					If pbOverWrite = False And bDestExists = True Then GoTo CatchDestinationExists
					bCreateFolder = False
				Case False	&apos; Folder
					If Not .FolderExists(psSource) Then GoTo CatchSourceFolderNotExists
					If Not .FolderExists(.GetParentFolderName(psDestination)) Then GoTo CatchDestFolderNotExists
					If .FileExists(psDestination) Then GoTo CatchFileNotFolder
					bDestExists = .FolderExists(psDestination)
					If pbOverWrite = False And bDestExists Then GoTo CatchDestinationExists
					bCreateFolder = Not bDestExists
			End Select
		End If

Try:
		Set oSfa = SF_Utils._GetUnoService(&quot;FileAccess&quot;)
		If bWildCards Then
			If bFile Then vFiles = .Files(sParentFolder, .GetName(psSource)) Else vFiles = .SubFolders(sParentFolder, .GetName(psSource))
			If UBound(vFiles) &lt; 0 Then GoTo CatchNoMatch
			&apos;	Go through the candidates
			If bCreateFolder Then .CreateFolder(psDestination)
			For i = 0 To UBound(vFiles)
				sFile = vFiles(i)
				sDestinationFile = .BuildPath(psDestination, .GetName(sFile))
				If bFile Then bDestExists = .FileExists(sDestinationFile) Else bDestExists = .FolderExists(sDestinationFile)
				If pbOverWrite = False Then
					If bDestExists Then GoTo CatchDestinationExists
					If .FolderExists(sDestinationFile) Then GoTo CatchDestinationExists
				End If
				sSourceUrl = ._ConvertToUrl(sFile)
				sDestinationUrl = ._ConvertToUrl(sDestinationFile)
				If bDestExists Then
					If oSfa.isReadOnly(sDestinationUrl) Then GoTo CatchDestinationReadOnly
				End If
				Select Case bCopy
					Case True	:	oSfa.copy(sSourceUrl, sDestinationUrl)
					Case False	:	oSfa.move(sSourceUrl, sDestinationUrl)
				End Select
			Next i
		Else
			sSourceUrl = ._ConvertToUrl(psSource)
			sDestinationUrl = ._ConvertToUrl(psDestination)
			If bDestExists Then
				If oSfa.isReadOnly(sDestinationUrl) Then GoTo CatchDestinationReadOnly
			End If
			If bCreateFolder Then .CreateFolder(psDestination)
			Select Case bCopy
				Case True	:	oSfa.copy(sSourceUrl, sDestinationUrl)
				Case False	:	oSfa.move(sSourceUrl, sDestinationUrl)
			End Select
		End If

	End With

	bCopyMove = True

Finally:
	_CopyMove = bCopyMove
	Exit Function
CatchFileNotExists:
	SF_Exception.RaiseFatal(UNKNOWNFILEERROR, &quot;Source&quot;, psSource)
	GoTo Finally
CatchSourceFolderNotExists:
	SF_Exception.RaiseFatal(UNKNOWNFOLDERERROR, &quot;Source&quot;, psSource)
	GoTo Finally
CatchDestFolderNotExists:
	SF_Exception.RaiseFatal(UNKNOWNFOLDERERROR, &quot;Destination&quot;, psDestination)
	GoTo Finally
CatchFolderNotFile:
	SF_Exception.RaiseFatal(NOTAFILEERROR, &quot;Destination&quot;, psDestination)
	GoTo Finally
CatchDestinationExists:
	SF_Exception.RaiseFatal(OVERWRITEERROR, &quot;Destination&quot;, psDestination)
	GoTo Finally
CatchNoMatch:
	SF_Exception.RaiseFatal(NOFILEMATCHERROR, &quot;Source&quot;, psSource)
	GoTo Finally
CatchFileNotFolder:
	SF_Exception.RaiseFatal(NOTAFOLDERERROR, &quot;Destination&quot;, psDestination)
	GoTo Finally
CatchDestinationReadOnly:
	SF_Exception.RaiseFatal(READONLYERROR, &quot;Destination&quot;, Iif(bWildCards, sDestinationFile, psDestination))
	GoTo Finally
End Function	&apos;	ScriptForge.SF_FileSystem._CopyMove

REM -----------------------------------------------------------------------------
Public Function _CountTextLines(ByVal psFileName As String _
									, Optional ByVal pbIncludeBlanks As Boolean _
									) As Long
&apos;&apos;&apos;	Convenient function to count the number of lines in a textfile
&apos;&apos;&apos;	Args:
&apos;&apos;&apos;		psFileName: the file in FileNaming notation
&apos;&apos;&apos;		pbIncludeBlanks: if True (default), zero-length lines are included
&apos;&apos;&apos;	Returns:
&apos;&apos;&apos;		The number of lines, f.i. to ease array sizing. -1 if file reading error

Dim lLines As Long			&apos;	Return value
Dim oFile As Object			&apos;	File handler
Dim sLine As String			&apos;	The last line read

Try:
	lLines = 0
	If IsMissing(pbIncludeBlanks) Then pbIncludeBlanks = True
	Set oFile = SF_FileSystem.OpenTextFile(psFileName, ForReading)
	With oFile
		If Not IsNull(oFile) Then
			Do While Not .AtEndOfStream
				sLine = .ReadLine()
				lLines = lLines + Iif(Len(sLine) &gt; 0 Or pbIncludeBlanks, 1, 0)
			Loop
		End If
		.CloseFile()
		Set oFile = .Dispose()
	End With

Finally:
	_CountTextLines = lLines
	Exit Function
End Function	&apos;	ScriptForge.SF_FileSystem._CountTextLines

REM -----------------------------------------------------------------------------
Private Function _Delete(psMethod As String _
								, psFile As String _
								) As Boolean
&apos;&apos;&apos;	Checks the argument and executes the given psMethod
&apos;&apos;&apos;	Args:
&apos;&apos;&apos;		psMethod: CopyFile/CopyFolder or MoveFile/MoveFolder
&apos;&apos;&apos;		psFile: Either File/FolderName
&apos;&apos;&apos;					or NamePattern which can include wildcard characters, for one or more files/folders to be deleted
&apos;&apos;&apos;	Next checks are done:
&apos;&apos;&apos;		With wildcards (multiple files/folders):
&apos;&apos;&apos;			- Parent folder of File must exist
&apos;&apos;&apos;			- At least one file matches the wildcards expression
&apos;&apos;&apos;			- Files or folders to delete must not have the read-only attribute set
&apos;&apos;&apos;		Without wildcards (single file/folder):
&apos;&apos;&apos;			- File/folder must exist and be a file/folder
&apos;&apos;&apos;			- A file or folder to delete must not have the read-only attribute set

Dim bDelete As Boolean			&apos;	Return value
Dim bFile As Boolean			&apos;	True if File, False if Folder
Dim oSfa As Object				&apos;	com.sun.star.ucb.SimpleFileAccess
Dim bWildCards As Boolean		&apos;	True if wildcards found in File
Dim sFileUrl As String			&apos;	Alias for File
Dim sParentFolder As String		&apos;	Parent folder of File
Dim vFiles As Variant			&apos;	Array of candidates for deletion
Dim sFile As String				&apos;	Single file/folder
Dim sName As String				&apos;	Name (last component) of file
Dim i As Long

	&apos;	Error handling left to calling routine
	bDelete = False
	bFile = ( Right(psMethod, 4) = &quot;File&quot; )
	bWildCards = ( InStr(psFile, &quot;*&quot;) + InStr(psFile, &quot;?&quot;) + InStr(psFile, &quot;%3F&quot;) &gt; 0 )	&apos;ConvertToUrl() converts sometimes &quot;?&quot; to &quot;%3F&quot;

	With SF_FileSystem

Check:
		If bWildCards Then
			sParentFolder = .GetParentFolderName(psFile)
			If Not .FolderExists(sParentFolder) Then GoTo CatchNoMatch
		Else
			Select Case bFile
				Case True 	&apos; File
					If .FolderExists(psFile) Then GoTo CatchFolderNotFile
					If Not .FileExists(psFile) Then GoTo CatchFileNotExists
				Case False	&apos; Folder
					If .FileExists(psFile) Then GoTo CatchFileNotFolder
					If Not .FolderExists(psFile) Then GoTo CatchFolderNotExists
			End Select
		End If

Try:
		Set oSfa = SF_Utils._GetUnoService(&quot;FileAccess&quot;)
		If bWildCards Then
			If bFile Then vFiles = .Files(sParentFolder) Else vFiles = .SubFolders(sParentFolder)
			&apos;	Select candidates
			For i = 0 To UBound(vFiles)
				If Not SF_String.IsLike(.GetName(vFiles(i)), .GetName(psFile)) Then vFiles(i) = &quot;&quot;
			Next i
			vFiles = SF_Array.TrimArray(vFiles)
			If UBound(vFiles) &lt; 0 Then GoTo CatchNoMatch
			&apos;	Go through the candidates
			For i = 0 To UBound(vFiles)
				sFile = vFiles(i)
				sFileUrl = ._ConvertToUrl(sFile)
				If oSfa.isReadOnly(sFileUrl) Then GoTo CatchReadOnly
				oSfa.kill(sFileUrl)
			Next i
		Else
			sFileUrl = ._ConvertToUrl(psFile)
			If oSfa.isReadOnly(sFileUrl) Then GoTo CatchReadOnly
			oSfa.kill(sFileUrl)
		End If

	End With

	bDelete = True

Finally:
	_Delete = bDelete
	Exit Function
CatchFolderNotExists:
	SF_Exception.RaiseFatal(UNKNOWNFOLDERERROR, &quot;FolderName&quot;, psFile)
	GoTo Finally
CatchFileNotExists:
	SF_Exception.RaiseFatal(UNKNOWNFILEERROR, &quot;FileName&quot;, psFile)
	GoTo Finally
CatchFolderNotFile:
	SF_Exception.RaiseFatal(NOTAFILEERROR, &quot;FileName&quot;, psFile)
	GoTo Finally
CatchNoMatch:
	SF_Exception.RaiseFatal(NOFILEMATCHERROR, Iif(bFile, &quot;FileName&quot;, &quot;FolderName&quot;), psFile)
	GoTo Finally
CatchFileNotFolder:
	SF_Exception.RaiseFatal(NOTAFOLDERERROR, &quot;FolderName&quot;, psFile)
	GoTo Finally
CatchReadOnly:
	SF_Exception.RaiseFatal(READONLYERROR, Iif(bFile, &quot;FileName&quot;, &quot;FolderName&quot;), Iif(bWildCards, sFile, psFile))
	GoTo Finally
End Function	&apos;	ScriptForge.SF_FileSystem._Delete

REM -----------------------------------------------------------------------------
Private Function _GetConfigFolder(ByVal psFolder As String) As String
&apos;&apos;&apos;	Returns one of next configuration folders: see https://api.libreoffice.org/docs/idl/ref/servicecom_1_1sun_1_1star_1_1util_1_1PathSubstitution.html
&apos;&apos;&apos;		inst =&gt; Installation path of LibreOffice
&apos;&apos;&apos;		prog =&gt; Program path of LibreOffice
&apos;&apos;&apos;		user =&gt; The user installation/config directory
&apos;&apos;&apos;		work =&gt; The work directory of the user. Under Windows this would be the &quot;MyDocuments&quot; subdirectory. Under Unix this would be the home-directory
&apos;&apos;&apos;		home =&gt; The home directory of the user. Under Unix this would be the home- directory. 
&apos;&apos;&apos;				Under Windows this would be the CSIDL_PERSONAL directory, for example &quot;Documents and Settings\&lt;username&gt;\Documents&quot;
&apos;&apos;&apos;		temp =&gt; The current temporary directory

Dim oSubst As Object		&apos;	com.sun.star.util.PathSubstitution
Dim sConfig As String		&apos;	Return value

	sConfig = &quot;&quot;
	Set oSubst = SF_Utils._GetUNOService(&quot;PathSubstitution&quot;)
	If Not IsNull(oSubst) Then sConfig = oSubst.getSubstituteVariableValue(&quot;$(&quot; &amp; psFolder &amp; &quot;)&quot;) &amp; &quot;/&quot;

	_GetConfigFolder = SF_FileSystem._ConvertFromUrl(sConfig)

End Function	&apos;	ScriptForge.FileSystem._GetConfigFolder

REM -----------------------------------------------------------------------------
Public Function _ParseUrl(psUrl As String) As Object
&apos;&apos;&apos;	Returns a com.sun.star.util.URL structure based on the argument

Dim oParse As Object					&apos;	com.sun.star.util.URLTransformer
Dim bParsed As Boolean					&apos;	True if parsing is successful
Dim oUrl As New com.sun.star.util.URL	&apos;	Return value

	oUrl.Complete = psUrl
	Set oParse = SF_Utils._GetUNOService(&quot;URLTransformer&quot;)
	bParsed = oParse.parseStrict(oUrl, &quot;&quot;)
	If bParsed Then oUrl.Path = ConvertToUrl(oUrl.Path)

	Set _ParseUrl = oUrl

End Function	&apos;	ScriptForge.SF_FileSystem._ParseUrl

REM -----------------------------------------------------------------------------
Public Function _SFInstallFolder() As String
&apos;&apos;&apos;	Returns the installation folder of the ScriptForge library
&apos;&apos;&apos;	Either:
&apos;&apos;&apos;		- The library is present in [My Macros &amp; Dialogs]
&apos;&apos;&apos;			($config)/basic/ScriptForge
&apos;&apos;&apos;		- The library is present in [LibreOffice Macros &amp; Dialogs]
&apos;&apos;&apos;			($install)/share/basic/ScriptForge

Dim sFolder As String		&apos;	Folder

	_SFInstallFolder = &quot;&quot;

	sFolder = BuildPath(ConfigFolder, &quot;basic/ScriptForge&quot;)
	If Not FolderExists(sFolder) Then
		sFolder = BuildPath(InstallFolder, &quot;share/basic/ScriptForge&quot;)
		If Not FolderExists(sFolder) Then Exit Function
	End If

	_SFInstallFolder = _ConvertFromUrl(sFolder)

End Function	&apos;	ScriptForge.SF_FileSystem._SFInstallFolder

REM ============================================ END OF SCRIPTFORGE.SF_FileSystem
</script:module>