Actionscript 3 从文件中获取文件名
我有以下代码:Actionscript 3 从文件中获取文件名,actionscript-3,Actionscript 3,我有以下代码: private function uploadFile(file:File, packageId:String):void { try { var fullpath:String = file.nativePath; var filename:String = fullpath.substr(fullpath.lastIndexOf("/")+1,fullpath.length);
private function uploadFile(file:File, packageId:String):void {
try {
var fullpath:String = file.nativePath;
var filename:String = fullpath.substr(fullpath.lastIndexOf("/")+1,fullpath.length);
packageItem.status = "Uploading file: "+filename;
file.addEventListener(ProgressEvent.PROGRESS, function(event:ProgressEvent):void{uploadProgress(event, packageId)} );
file.addEventListener(flash.events.Event.COMPLETE, function(event:flash.events.Event):void{uploadComplete(event, packageId)} );
file.upload(urlRequest, packageId);
} catch (error:Error) {
logging.log(error.message);
}
}
因此,我从文件对象的路径中提取文件名
这些文件来自:
File.applicationStorageDirectory
问题是,这对windows不起作用,因为他们使用反斜杠,而不是像MacOSX那样使用斜杠。将文件名和文件分开以便在mac和windows上工作的最佳方法是什么?这是相当明显的
url
属性具有文件的文件系统url。因此,具有nativePath
的文件
C:\Documents and Settings\some\u file.txt
将有一个url
file:///C:/Documents%20and%20Settings/some_file.txt
现在,您只需在/
上拆分即可
注意:您可能必须输入文件名才能删除url类型格式