Forum Discussion

thexder1's avatar
thexder1
Contributor
12 years ago

Using jscript to delete a directory and all contents

Below is code that I am trying to use to remove directories and all contents, but each time it runs the if statements work, but the DeleteFolder statements give me a path not found error.




function removeDirectories(clientDirectory, processExportDirectory, extractExportDirectory) {



var fso = new ActiveXObject("Scripting.FileSystemObject");



if (fso.folderExists(clientDirectory)) {



fso.DeleteFolder(clientDirectory);



}



if (fso.folderExists(processExportDirectory)) {



fso.DeleteFolder(processExportDirectory);



}



if (fso.folderExists(extractExportDirectory)) {



fso.DeleteFolder(extractExportDirectory);



}



}


  • If it makes any difference I found that I do not run into the error if the directory is local, only if it is on a network share, either UNC path or Mapped drive gives the same results. Once again the if statements work on UNC, Mapped drive, and local paths.
  • I figured out the issue, Apparently if you try to delete any file or folder that has a path longer than 255 characters you get the path not found error. Until I can find a work around I have changed it to move the folder instead of deleting it.