var fs=require('fs');

var options={
    encoding:'utf8',
    withFileTypes:true
}

var renameFile=function(path){
    console.log('当前目录:'+path);
    fs.readdir(path,options,(err,files)=>{
        files.forEach(element => {
            if(element.isDirectory()){//目录
                var oldDirName=element.name;
                var curDirPath=path+"\\"+oldDirName;
                var newDirPath=path+"\\"+oldDirName.toLocaleLowerCase();
                fs.rename(curDirPath,newDirPath,() =>{
                    console.log('重命名 '+curDirPath+' 为小写成功!下面重命名子文件夹!');
                });
                renameFile(newDirPath);
            }else{//文件
                var oldFileName=element.name;
                var curFileFullPath=path+"\\"+oldFileName;
                var newFileFullPath=path+'\\'+oldFileName.toLocaleLowerCase();
                fs.rename(curFileFullPath,newFileFullPath,() =>{
                    console.log('重命名 '+curFileFullPath+' 为小写成功!');
                });
            }
        });
    })
}

renameFile("path");

 

相关文章:

  • 2021-09-03
  • 2021-10-10
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-06
  • 2021-10-29
  • 2021-09-21
猜你喜欢
  • 2022-12-23
  • 2022-01-16
  • 2022-12-23
  • 2022-12-23
  • 2021-08-10
  • 2021-07-08
  • 2022-01-20
相关资源
相似解决方案