JavaScript gets the directory where the currently running script files are located

  • 2020-12-18 01:44:46
  • OfStack

This article example shows how JavaScript gets the directory where the currently running script files are located. To share for your reference, the details are as follows:


DirectoryUtility = {
  // function getCurrentDirectory: returns currentDirectory path 
  // with a trailing backslash.
  getCurrentDirectory : function ( ) {
    var scriptFullName = WScript.ScriptFullName;
    var scriptName = WScript.ScriptName;
    return scriptFullName.substr ( 0, scriptFullName.lastIndexOf ( scriptName ) );
  }
}
/*  usage  */
DirectoryUtility.getCurrentDirectory ( );

For more information about JavaScript, please refer to: Summary of JavaScript Data Structure and Algorithm Techniques, javascript Object-oriented Tutorial and JavaScript Algorithm Techniques Summary.

I hope this article has been helpful in JavaScript programming.


Related articles: