Skip to main content
johnt53984649
Inspiring
June 21, 2020
Question

How to change working directory in extendscript?

  • June 21, 2020
  • 1 reply
  • 1105 views

Whenever I run a script file, it seems that the working directory is the same directory that the script is located at. However, suppose I want to change the current working directory at run time, including directories which may be located on different drives which may include spaces in their name. How would I do this in ExtendScript?

 

The reason that I ask is because I have ExtendScript running other files that expect to be run from specific directories, and I need to change the current working directory before I run them.

This topic has been closed for replies.

1 reply

Mylenium
Legend
June 21, 2020

I'm not clear what you are asking. You should not have any issues by pointing to other folders using their URIs or invoking extra file dialogs. The only thing of concern are potential limitations due to user permissions and other security stuff.

 

Mylenium

johnt53984649
Inspiring
June 21, 2020

Here's an example of what I mean. If I have a Python script that is located in a different directory than the .jsx script and I call it from the .jsx script with something like:

 

system.callSystem("cmd.exe /c pathToMyPythonScript.py"")
 
and the Python script tries to access files using paths that are located in directories specified relative to itself (such as "../template.txt", or "out/template.txt"), then the Python script is unable to find that txt file because when it is run, it's being run with the current working directory set to the .jsx script, not the Python script. I was wondering if there is any native way in ExtendScript to set the current working directory so that when I call the Python script, it is being run from whatever I set the CWD to in ExtendScript.
 
An example of how to do this in Python would be os.chdir(newdirectory). I was simply wondering if there was any way to do it in ExtendScript directly.
Mathias Moehl
Community Expert
Community Expert
June 22, 2020

instead of executing the python script directly, you could execute a bat file (or on Mac a shell script) that first changes to that directory and then executes the script.

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects