1. //showFile -src
    2. let argv = process.argv[2].slice(1);
    3. const path = require('path');
    4. const fs = require('fs');
    5. //__dirname:当前所在js文件的绝对路径
    6. //process.cwd():小黑板打开的绝对路径
    7. let url = path.join(process.cwd(),argv); //拼接路径
    8. function read(url){
    9. // console.log(__dirname);
    10. // console.log("process",process.cwd())
    11. if(fs.existsSync(url)){
    12. //1.先读取目录
    13. letlist = fs.readdirSync(url); //[css,index.html]
    14. list.forEach(file=> {
    15. letcurUrl =path.join(url,file);
    16. //2.判断当前路径是文件还是文件夹
    17. if(fs.statSync(curUrl).isDirectory()){
    18. console.log(file)
    19. //是文件夹
    20. read(curUrl)
    21. }else{
    22. //是文件
    23. console.log(file)
    24. }
    25. })
    26. }else{
    27. console.log("当前路径不合法")
    28. }
    29. }
    30. read(url)