dimanche 24 octobre 2021

How to input single backslash for location input in node.js instead of double backslash?

I am building a application where user input a word to be searched in the files and the location of the folder. But I am unble to create a code where user will input the location in single backslash , instead he have to input double backslash in place of single .

const folderAddress=prompt('Enter Folder Address (replace \ with \\)= '); 

const tags=prompt('Enter tags= ');
 let Assets=tags.split(',');
 let allAssets=(Object.values(Assets));
 //console.log('Assets list= '+allAssets);

 const files=getAllFiles(folderAddress);
 let allFiles=Object.values(files);
 //console.log('file list= '+allFiles);

 let ourFile='C:\\Users\\bagde\\Desktop\\JavaScriptPractice\\Demo.html';

 fs.writeFile(ourFile,' ',function(err){}); // this line will removing all thing in demo.html
    let htm=getFileData('C:\\Users\\bagde\\Desktop\\JavaScriptPractice\\index.html');
    writeIntoFile(ourFile,htm);
 
 for(let i=0;i<allAssets.length;i++){
     let count=0;
     let f=0;
     for(let j=0;j<allFiles.length;j++){
         let add=folderAddress+'\\\\'+allFiles[j];
         let data=getFileData(add);
        // console.log('Complete address= '+add);
         let pCount=countOccurences(data,allAssets[i]);
          if(pCount>0){
              f++;
          }  
         count+=pCount;
     }
     console.log(allAssets[i]+" - Found "+count+" occurrence in "+f+" files");
     fs.appendFile(ourFile,'<tr><td>808Ab</td><td>dummy data</td><td>'+allAssets[i]+'</td><td>dummy data</td><td>  Found '+count+' occurrence in '+f+' files </td></tr>',function(err){});
 }



Aucun commentaire:

Enregistrer un commentaire