仅包含 pdf 文件的 ListDir
ListDir which contains only pdf files
我需要有关 Ionic-4 的帮助code.I 想使用 lisDir 方法列出其中仅包含 PDF 文件的目录。
提前致谢。
试试下面的代码,这应该在 Android 中有效,我没有时间测试它但应该有效;
constructor(public navCtrl: NavController, public platform: Platform,
private filePath: FilePath, private file: File) {
this.platform.ready().then(() => {
this.file.listDir(file.externalDataDirectory, '').then((result) => {
console.log(result);
for (const fl of result) {
if (fl.isDirectory == true && fl.name != '.' && fl.name != '..') {
// Code if its a folder
} else if (fl.isFile == true) {
const fName = fl.name; // File name
const path = fl.fullPath; // File path
if(fName.toLowerCase().endsWith('.pdf')) {
// do Something
}
}
}
});
});
}
我需要有关 Ionic-4 的帮助code.I 想使用 lisDir 方法列出其中仅包含 PDF 文件的目录。
提前致谢。
试试下面的代码,这应该在 Android 中有效,我没有时间测试它但应该有效;
constructor(public navCtrl: NavController, public platform: Platform,
private filePath: FilePath, private file: File) {
this.platform.ready().then(() => {
this.file.listDir(file.externalDataDirectory, '').then((result) => {
console.log(result);
for (const fl of result) {
if (fl.isDirectory == true && fl.name != '.' && fl.name != '..') {
// Code if its a folder
} else if (fl.isFile == true) {
const fName = fl.name; // File name
const path = fl.fullPath; // File path
if(fName.toLowerCase().endsWith('.pdf')) {
// do Something
}
}
}
});
});
}