File 使用as3打开文件位置

File 使用as3打开文件位置,file,actionscript-3,air,File,Actionscript 3,Air,我有一个,其中包含一堆文件。在鼠标右键单击时,我在鼠标的(x,y)位置打开一个菜单,允许用户“打开文件位置”。我的难题是打开文件位置并选择(不打开)文件,就像Windows的资源管理器一样。打开父文件夹并使用file.openWithDefaultApplication()是我最接近的方法,打开文件所在的文件夹,但不向用户显示实际文件 mxml <s:List id="fileDownList" height="100%"

我有一个
,其中包含一堆
文件。在鼠标右键单击时,我在鼠标的(x,y)位置打开一个菜单,允许用户“打开文件位置”。我的难题是打开文件位置并选择(不打开)文件,就像Windows的资源管理器一样。打开父文件夹并使用
file.openWithDefaultApplication()是我最接近的方法,打开文件所在的文件夹,但不向用户显示实际文件

mxml

        <s:List
            id="fileDownList"
            height="100%"
            width="100%"
            dataProvider="{files}"
            labelField="name"
            allowMultipleSelection="false"
            rightClick="rightMouseDown(event)"
            itemRollOver="currentItem = event.itemRenderer.data"
            />
示例


尝试一下。。。事实证明,可以使用NativeProcess和一些
Explorer.exe
参数

这里有一个基本的AS3唯一的例子。请测试并在代码中应用逻辑:

//# String holds required file path
//# example ::: myfileURL = "C:\\myFolder\\mySubFolder\\myImage.jpg";
public var myfileURL : String = "";

myfileURL = "C:\\VC1\\Tests\\CoolSong.mp3"; //update this before running function
openWindows_FileSelected(); //run the function

private function openWindows_FileSelected ():void  
{  
    var explorer:File = new File("C:\\Windows\\explorer.exe");

    if (explorer.exists)  
    {  
        var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();  
        nativeProcessStartupInfo.executable = explorer;  

        var args:Vector.<String> = new Vector.<String>();  

        args.push("/select,"); 
        args.push( myfileURL ); //file to auto-highlight

        nativeProcessStartupInfo.arguments = args;  
        process = new NativeProcess();  
        process.start(nativeProcessStartupInfo);  
    }  

} 
/#字符串保存所需的文件路径
//#示例:::myfileURL=“C:\\myFolder\\mySubFolder\\myImage.jpg”;
public var myfileURL:String=“”;
myfileURL=“C:\\VC1\\Tests\\CoolSong.mp3”//在运行函数之前更新此选项
openWindows_FileSelected()//运行函数
私有函数openWindows\u FileSelected():void
{  
var explorer:File=新文件(“C:\\Windows\\explorer.exe”);
if(explorer.exists)
{  
var nativeProcessStartupInfo:nativeProcessStartupInfo=new nativeProcessStartupInfo();
nativeProcessStartupInfo.executable=explorer;
变量args:Vector.=新向量。();
args.push(“/select”);
args.push(myfileURL);//要自动突出显示的文件
nativeProcessStartupInfo.arguments=args;
进程=新的NativeProcess();
进程启动(nativeProcessStartupInfo);
}  
} 

PS:

我能想到的唯一一件事。。。由于您使用的是
文件
,因此必须通过文件的
.nativePath
命令获取其路径字符串,该命令将给出如下字符串:
“C:/myFolder/mySubFolder/myImage.jpg”


但要使上述代码正常工作,您必须进行替换(尝试字符串方法
Split/Join
),并使其看起来像:
“C:\\myFolder\\mySubFolder\\myImage.jpg”


如果您不将所有单正斜杠替换为双反斜杠,那么
Explorer.exe将不喜欢它,并且您将始终得到一个错误…

我最后做的是创建一个.cmd文件(只是一个重命名的.bat文件),该文件打开一个带有
/select
参数的目录

AS3

    private function rightMouseDown(event:MouseEvent):void {
        createMenu(currentItem, event.stageX, event.stageY);
    }

        private function createMenu(item:Object, xPos:int, yPos:int):void {
        if (menu != null) {
            menu.hide();
        }
        var menuItems:Array = [];

        menuItems.push({label:"Open File Location"),
            func: function run():void{
                //runs on doMenuAction listener, need to open location here

            }

        });

        if (menuItems.length > 0) {
            menu = Menu.createMenu(tree, menuItems);
            //noinspection JSValidateTypes
            menu.addEventListener(MenuEvent.ITEM_CLICK, doMenuAction);
        }

        if (menu != null) {
            menu.show(xPos, yPos);
        }

    }
private function run():void{
                        var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
                        var file:File = File.applicationDirectory.resolvePath("C:\\Users\\Me\\Desktop\\launcher.cmd");
                        nativeProcessStartupInfo.executable = file;

                        var processArgs:Vector.<String> = new Vector.<String>();
                        processArgs[0] = item.url;
                        nativeProcessStartupInfo.arguments = processArgs;

                        process = new NativeProcess();
                        process.start(nativeProcessStartupInfo);

                    }

不清楚你在问什么。还有-基于浏览器?空气?什么部分不清楚,我可以澄清一下?这是一个AIR桌面应用程序。@Sleeper,您是否使用过Windows文件搜索??当它给你一个文件名列表时,你可以右键单击其中一个,然后选择“打开文件位置”,这将打开一个新的浏览器窗口,并自动向下滚动到所述文件,其中自动高亮显示/为你选择…@Jordan.J.D,我不知道这是否可行。可能有一个windows CMD终端命令,您可以执行(作为NativeProcess?)来突出显示预期的文件。你必须到处搜索,然后see@Sleeper,如果您还需要什么,请告诉我。文件有一个
url
属性,您可以使用它来代替拆分和加入。啊!!我应该想到这一点。仍然是新的空中代码。你的问题是我第三次尝试了。只需要将AS3代码重新编译到Android。
@ECHO OFF
SET /a LOCATION=%1
explorer /select, %1