本文整理汇总了TypeScript中fs.promises.readdir方法的典型用法代码示例。如果您正苦于以下问题:TypeScript promises.readdir方法的具体用法?TypeScript promises.readdir怎么用?TypeScript promises.readdir使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fs.promises
的用法示例。
在下文中一共展示了promises.readdir方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: getAvailablePictures
async function getAvailablePictures() {
const rawavailablePictures = await fs.readdir(path.resolve(picturePath));
const availablePictures = rawavailablePictures.filter(
fileName => fileName.includes('.') && !fileName.endsWith('.zip')
);
return availablePictures;
}
示例2: prepare_posts
async function prepare_posts() {
const dir = `${__dirname}/posts/`;
const folders = await readdir(dir);
for (const folder of folders) {
// TODO: Make parallel
const data = await readFile(`${dir}${folder}/data.json`, "utf8");
let post_data = JSON.parse(data);
const post = await readFile(`${dir}${folder}/post.md`, "utf8");
marked(post, (err, content) => {
post_data["text"] = content;
posts[post_data.title.replace(/ /g, "_")] = post_data;
});
}
}
示例3:
}, () => {
});
fs.mkdirSync('some/test/path', {
recursive: true,
mode: 0o777,
});
}
{
let names: Promise<string[]>;
let buffers: Promise<Buffer[]>;
let namesOrBuffers: Promise<string[] | Buffer[]>;
let entries: Promise<fs.Dirent[]>;
names = fs.promises.readdir('/path/to/dir', { encoding: 'utf8', withFileTypes: false });
buffers = fs.promises.readdir('/path/to/dir', { encoding: 'buffer', withFileTypes: false });
namesOrBuffers = fs.promises.readdir('/path/to/dir', { encoding: 'SOME OTHER', withFileTypes: false });
entries = fs.promises.readdir('/path/to/dir', { encoding: 'utf8', withFileTypes: true });
}
}
////////////////////////////////////////////////////
/// Url tests : http://nodejs.org/api/url.html
////////////////////////////////////////////////////
{
{
url.format(url.parse('http://www.example.com/xyz'));
url.format('http://www.example.com/xyz');