Problem with Simple File Access method SFA.getFolderContents

First line in the Calc sheet sheet1 contains “Cutlery.txt”, “Furniture.txt”, “Medical supply.txt” in columns A, B, C.
Macro1 creates 3 files in the folder Arch, using content of A1, B1, C1 as their names: Cutlery.txt, Furniture.txt, Medical supply.txt.
Then macro2 creates an array sArr witn all file names in Arch using SFA.getFolderContents and then matches elements of sArr with the first line of the sheet1. Result: Cutlery.txt - matched, Furniture.txt - matched, Medical supply.txt – oops – not matched.
As it turned out, sArr(2) = “Medical%20supply.txt” , and it doesn’t match with “Medical supply.txt”.
Is it a problem with SFA.getFolderContents? Or should I match sArr with first line elements not through “=”, but in some other way?
Calc file Test_SFAgetFolder.ods uploaded. Button “Create files” creates 3 files in subfolder Arch (must exists), button “Check files” matches files in Arch with sheet1 first line.
Version: 6.3.6.2 (x64)
Build ID: 2196df99b074d8a661f4036fca8fa0cbfa33a497
CPU threads: 8; OS: Windows 10.0; UI render: default; VCL: win;
Locale: fr-FR (en_US); UI-Language: en-US
Calc: threaded
Test_SFAgetFolder.ods (12.4 KB)

apply the ENCODEURL function URI Functions before checking for equality

Hallo

from uno import fileUrlToSystemPath as to_path
from pathlib import Path

def create_files():
    doc = XSCRIPTCONTEXT.getDocument()
    file_names = doc.Sheets["Sheet1"]["A1:C1"].DataArray[0]
    base = Path( to_path(doc.URL) ).parent / "arch"
    base.mkdir(exist_ok=True)
    for file_name in file_names:
        (base / file_name).touch()

def check_exist():
    doc = XSCRIPTCONTEXT.getDocument()
    file_names = doc.Sheets["Sheet1"]["A1:C1"].DataArray[0]
    base = Path( to_path(doc.URL) ).parent / "arch"
    for file_name in file_names:
        p = base / file_name
        print(f'{p.name=}: {"exists" if p.exists() else " dont exist"}')
sFileName = ConvertFromUrl(Mid(sArr(i), iLen + 1))

Test_SFAgetFolder.ods (14.0 KB)

1 Like