简体   繁体   English

Adobe AIR - 读取 AIR package 外部同一文件夹中的文件

[英]Adobe AIR - reading a file in the same folder outside AIR package

How may I know File.nativepath from the folder that my.app or.exe AIR app is running?我如何从 my.app 或 .exe AIR 应用程序正在运行的文件夹中知道 File.nativepath? When I try this I just get当我尝试这个时,我得到了

'/Users/MYNAME/Desktop/MYAPP/Contents/Resources/FILETHATINEED.xml' '/Users/MYNAME/Desktop/MYAPP/Contents/Resources/FILETHATINEED.xml'

I need put this on any folder and read a xml file in the same folder.我需要将它放在任何文件夹中,并在同一文件夹中读取 xml 文件。 I don't need my xml file inside the package.我不需要 package 中的 xml 文件。

I need this structure我需要这个结构

/folder/AIRAPP.exe /文件夹/AIRAPP.exe

/folder/FILE.xml /文件夹/FILE.xml

Thanx in advance.提前谢谢。

From what I can find there is no way to get that without doing some work yourself.据我所知,如果不自己做一些工作,就没有办法做到这一点。 If we assume that the File.applicationDirectory points to the wrong place only on Mac (which seems like the case), we can do this:如果我们假设File.applicationDirectory仅在 Mac 上指向错误的位置(似乎是这种情况),我们可以这样做:

var appDir = File.applicationDirectory

if ( appDir.resolvePath("../../Contents/MacOS").exists ) {
  appDir = appDir.resolvePath("../../..");
}

That is, check if the parent directories of the app directory match the Mac.app bundle directory structure, and in that case use the parent's parent's parent (which should then be the directory containing the.app bundle).也就是说,检查 app 目录的父目录是否与 Mac.app 包目录结构匹配,在这种情况下使用父目录的父目录(应该是包含 .app 包的目录)。

I believe you want to use File.applicationDirectory.我相信你想使用 File.applicationDirectory。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM