Can't delete top level folders created with Node

Post Reply
PdFUser5000
Member
Posts: 120
Joined: Fri Jun 12, 2020 11:23 am

Can't delete top level folders created with Node

Post by PdFUser5000 »

I am trying to create a hierarchy with folders and add files inside them. But after creating the folders, i cant delete the top 2 levels of the folder hierarchy.

My hierarchy looks something like this

1st level: Folder 1 (Phoenix) Can't delete
2nd level: Folder 2 (modelName) Can't delete
3rd level: Folder 3 and Folder 4 ( PDF sizes and reports) Can delete these

Tried using 3 different functions, but the same problem still exists.

I Can delete the files with Node.
When trying to save to desktop, windows says the folder is no longer located ther, although it most certainly is.

Code: Select all

const fs = require('fs-extra');


async function jobArrived(s, flowElement, job) {
    
    try {

 let tempPath = await job.get(AccessLevel.ReadWrite);  //file path

 //data from switch for functions
 


 let originalPath = await flowElement.getPropertyStringValue("OriginPath"); 
 // new location for creating extra folders 

 let modelName = await flowElement.getPropertyStringValue("GetModelFolder");
 //folder name for creating folder modelName 

 let fileName = await flowElement.getPropertyStringValue("GetFileName");
//file name 




//create directories for files Phoenix folder + PDF sizes + Reports folder


async function CreateFLDRS (directory) {
    try {
      await fs.ensureDir(directory)
      await job.log(LogLevel.Info, "Folders created");
    } catch (err) {
      await job.log(LogLevel.Error, err.message);
    }
  };
 
  
 await CreateFLDRS(originalPath + "/Phoenix" +"/" + modelName + "/PDF sizes");
 await CreateFLDRS(originalPath + "/Phoenix" +"/" + modelName + "/Reports");

//move files to correct folder

let PDFloc = originalPath + "/Phoenix" +"/" + modelName + "/Reports" + "/" + fileName

      

async function MoveFile () {
  try {
    await fs.copy(tempPath,PDFloc)
    
  } catch (err) {
    await job.log(LogLevel.Error, err.message);
  }
};

await MoveFile(); 


 
       await job.sendToSingle(); 


}
catch(e) {
    await job.log(LogLevel.Error, e.message);
}

};
freddyp
Advanced member
Posts: 1008
Joined: Thu Feb 09, 2012 3:53 pm

Re: Can't delete top level folders created with Node

Post by freddyp »

I have not tested it but I can only assume that fs.ensureDir creates the directories with a mode that does not allow them to be deleted. fs.ensureDir takes a second parameter that specifies the access mode. Try adding that with the octal value 777 (you may know that from the command chmod) which is written as 0777, not 777! That is decimal and will not give the expected result.

One thing puzzles me, though. You say you can't delete folders but your code does not try to delete anything?
PdFUser5000
Member
Posts: 120
Joined: Fri Jun 12, 2020 11:23 am

Re: Can't delete top level folders created with Node

Post by PdFUser5000 »

freddyp wrote: Thu Feb 11, 2021 8:38 am I have not tested it but I can only assume that fs.ensureDir creates the directories with a mode that does not allow them to be deleted. fs.ensureDir takes a second parameter that specifies the access mode. Try adding that with the octal value 777 (you may know that from the command chmod) which is written as 0777, not 777! That is decimal and will not give the expected result.

One thing puzzles me, though. You say you can't delete folders but your code does not try to delete anything?
I want the user to be able to delete this folder manually.

Ok so what was wrong, was that i had a whitespace between 2 variables, which somehow changed the 2 top folders to read only. is there any way i can insert a whitespace there at all ?

[Metadata.Text:Path="/orderinfo/model/designID",Dataset="PPinfo",Model="XML"](space was here)[Metadata.Text:Path="/orderinfo/model/suffiks",Dataset="PPinfo",Model="XML",Space="trim"]
Post Reply