import { resolve, join, extname, basename, dirname } from 'node:path'; export function testJoin() { console.log(join('/foo', 'bar', 'baz/asdf', 'quux', '..')); } export function testResolve() { console.log(resolve('/foo/bar', './baz')); console.log(resolve('/foo/bar', '/tmp/file/')); console.log(resolve('wwwroot', 'static_files/png/', '../gif/image.gif')); // /users/daxia/documents/work/vip20/19_Node.js/day2/code/wwwroot/statci_files/git/image.gif // /Users/daxia/Documents/work/vip20/19_Node.js/day-2/code/wwwroot/static_files/gif/image.gif } // 其他 export function otherMethods() { const filePath = './a/b/c/d.md'; // 获取文件的扩展名 console.log('后缀名:', extname(filePath)); // 获取文件的完整名称(包含 后缀名) console.log('文件名:', basename(filePath)); // 文件的目录层级 console.log('文件的目录层级:', dirname(filePath)); }