HarmonyOS 鸿蒙Next怎么选择文件夹然后得到文件夹的路径?

发布于 1周前 作者 phonegap100 来自 鸿蒙OS

HarmonyOS 鸿蒙Next怎么选择文件夹然后得到文件夹的路径?

export async function readUserFile(maxSelectNumber:number,selectMode:number): Promise<string> {
let uri: string = ‘’;
let message: string = ‘’;
if(canIUse(‘SystemCapability.FileManagement.UserFileService.FolderSelection’)){
try {
let DocumentSelectOptions = new picker.DocumentSelectOptions();
DocumentSelectOptions.selectMode = selectMode
DocumentSelectOptions.maxSelectNumber = maxSelectNumber
let documentPicker = new picker.DocumentViewPicker();
await documentPicker.select(DocumentSelectOptions).then((DocumentSelectResult: Array<string>) => {
console.info('DocumentViewPicker.select successfully, uri: ’ + JSON.stringify(DocumentSelectResult));
uri = DocumentSelectResult[0];
let file = fileIo.openSync(uri, fileIo.OpenMode.READ_WRITE);
let stat = fileIo.statSync(file.fd);
let size = stat.size;
let buf = new ArrayBuffer(size);
fileIo.readSync(file.fd, buf);
let con = buffer.from(buf, 0);
message = con.toString();
console.info('DocumentViewPicker.select successfully, message: ’ + message);
return message;
}).catch((err: BusinessError) => {
console.error('DocumentViewPicker.select failed with err: ’ + JSON.stringify(err));
});
} catch (error) {
let err = error as BusinessError;
console.error('DocumentViewPicker.select failed with err: ’ + err.message);
}
}
return message;
}<button style="position: absolute; padding: 4px 8px 0px; cursor: pointer; top: 8px; right: 8px; font-size: 14px;">复制</button>

通过给DocumentSelectOptions.selectMode赋值1,选择的资源类型确实只有文件夹了,选定好某个文件夹之后,我要怎么确定选择当前文件夹? 没有提供一个确认的按钮吗?

cke_1856.png

或者有没有什么别的方法可以选择文件夹然后得到文件夹路径?



关于HarmonyOS 鸿蒙Next怎么选择文件夹然后得到文件夹的路径?的问题,您也可以访问:https://www.itying.com/category-93-b0.html 联系官网客服。

8 回复

找HarmonyOS工作还需要会Flutter的哦,有需要Flutter教程的可以学学大地老师的教程,很不错,B站免费学的哦:https://www.bilibili.com/video/BV1S4411E7LY/?p=17

楼主,这个问题你解决了嘛,我也遇到了相同的问题

有要学HarmonyOS AI的同学吗,联系我:https://www.itying.com/goods-1206.html

找HarmonyOS工作还需要会Flutter的哦,有需要Flutter教程的可以学学大地老师的教程,很不错,B站免费学的哦:https://www.bilibili.com/video/BV1S4411E7LY/?p=17

您好,可以参考三方库eftool里面的welcome文件中有详细的demo

公共目录下的文件夹路径有办法获取吗

您能具体说说吗,没有找到这个welcome文件

回到顶部