Frage

Weiß jemand, wie man das Arbeitsverzeichnis schon einmal in JavaScript festlegt?

Code, den ich zum Starten einer Anwendung verwende, ist Folgendes:

// Create an object script
oL = new ActiveXObject("WScript.Shell");
oFile = '"C:/Application.exe"';
oL.run(oFile);
War es hilfreich?

Lösung

According to MSDN, you should be able to use:

var oL = new ActiveXObject("WScript.Shell");
oL.CurrentDirectory = "C:\\Foo\\Bar";
oFile = '"C:\\Application.exe"';
oL.run(oFile);

...assuming you're running this script in Windows Script Host, in which case you probably ought to make that clear in your question - about 99% of JavaScript programmers only ever use the language in a web browser, where this kind of stuff is only possible under extremely unusual circumstances.

Andere Tipps

Javascript typically runs in a sandbox that means it doesn't have access to the filesystem anyway, thus setting the cwd is meaningless.

What context are you trying to do this in (website javascript, local script running with Rhino etc.) and what are you trying to achieve?

Javascript dosent have access to your harddrive so why should you be able to set the working directory?

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top