# Changing Working Directories In Nashorn Scripting

Assigning a directory name to the $ENV.PWD variable: $ENV.PWD="[DIR_NAME]" changes the working directory for the next command:


The ls command will print the contents for directory specified earlier:



#!/usr/bin/jjs -fv
print('Tmp Directory');
$ENV.PWD='/tmp';
$EXEC('ls -al');
print($OUT);
print('Root Directory');
$ENV.PWD='/';
$EXEC('ls -al');
print($OUT);



Thanks to Jim Laskey for the hint



See you at Java EE Workshops at Munich Airport or dedicated / custom virtual workshops!
