开头
我发布了一个素描插件,具有某些功能,在文件管理中具有很强的依赖性。
执行后,插件需要检查文件夹是否存在,如果不存在,则创建该文件夹,然后在此目录中管理几个文件。
几周前,一位用户报告插件正在新的草图版本中崩溃。
来自:
的意外响应-
fileExistsAtPath
返回-folder不存在 - 当该路径中实际存在时 -
createDirectoryAtPath
返回'错误'尝试创建一个不存在的文件夹时(我在存在文件夹时都测试了两个文件夹(
(
快速示例:
请求
var document = context.document
var documentName = document.displayName()
var documentFolderPath = decodeURIComponent(document.fileURL()).replace('file:///','').replace(documentName,"")
print(documentName)
print(documentFolderPath)
var translationsFolderName = documentName.replace('.sketch','_translations')
var translationsFolderPath = documentFolderPath+translationsFolderName+'/'
print(translationsFolderName)
print(translationsFolderPath)
var fileManager = [NSFileManager defaultManager];
if(![fileManager fileExistsAtPath:translationsFolderPath isDirectory:'YES'])
{
print(translationsFolderPath+" folder does not exist")
if(![fileManager createDirectoryAtPath:translationsFolderPath withIntermediateDirectories:'YES' attributes:nil error:nil])
{
print(translationsFolderPath+" folder can't be created")
}
}
响应
test.sketch
Users/myuser/Documents/
test_translations
Users/myuser/Documents/test_translations/
Users/myuser/Documents/test_translations/ folder does not exist
Users/myuser/Documents/test_translations/ folder can't be created
Script executed in 0.034733s
有什么想法吗?
谢谢!
您的文件路径没有扎根(不以/(