在我编译的 Livecode 桌面应用程序中,PC 版本按预期保存文件和文件夹。 Mac编译版本全错

In my compiled Livecode desktop app, the PC version saves files and folders as expected. The Mac compiled version is all wrong

在我的桌面应用程序中,我有一个非常明确的文件和文件夹结构:

main_folder ---folder2 ------file1 ------file2 ---folder3 ------file1 ------file2 etc...

在 PC 上,这写得很好。我定义主文件夹和子文件夹:

put "c:\folder1\folder2\file1" into someVariable

在 Mac,我有:

put specialfolderpath("Documents") & "/folder1/folder2/file1" into someVariable

在 PC 上,它按预期将文件写入文件夹。 Mac上好像写了一个folder/file组合:

/folder1/folder2/file1

作为一个文件。

为了让软件正常工作,我将 folder/file 结构复制到 Mac,因为它在 PC 上。

Mac 应用找不到现有文件,然后在现有 folders/files 下写入新文件作为新文件。

一切都很混乱,我只是不明白为什么它不能正常工作。

如果找不到现有文件,LiveCode 将创建一个新文件。

我认为使用 "specialFolderPath" 时无法连接文件夹。查看字典,它只给出了包含单个文件夹的示例。

试试这个:

answer folder "Select Folder"
put it into folderPath

检查局部变量 "it" 返回的内容。然后测试一下。

从您的问题中并不清楚您到底想做什么以及如何将文件写入您的文件夹结构。如果我要将文件写入您的应用程序文件夹结构,我会这样做(假设 main_folder 是您的独立应用程序所在的位置):

put "some text" into tTextString
put specialFolderPath("resources") & "/folder1/folder2/myfile.txt" into tPath
put textEncode(tTextString,"utf8") into URL ("binfile:" & tPath)
# textEncode is needed if you want to preserve unicode characters
# in your file, and is more reliable for cross-platform file exchange

SpecialFolderPath("resources") 表示你的栈在开发环境中保存的文件夹;在独立环境中,它是您的独立堆栈所在的文件夹。请注意,在 Mac 上,这是在应用程序包内。

顺便说一句,此脚本应该适用于 Mac 和 Windows,假设您对该文件夹具有写入权限。这是 not 已编译应用程序的给定,因此您可能想要使用 specialFolderPath("support") 或 specialFolderPath("documents"). SpecialFolderPath("resources") 是存储应用程序所需静态资产的好地方,但通常不适合从应用程序写入的文件。