How to check if directory exists outside of workspace from a jenkins pipeline script

Tried a few things and turned out the answer was already in front of me. fileExists can check for directories as well. Here's how I got around the problem. In this example, I am creating a directory on Windows if it doesn't exist.

Step 1: dir into the directory

dir("C:/_Tests")

Step 2: Now, use fileExists without any file name.

if(!fileExists("/"))
{
  bat "mkdir \"C:/_Tests\""
}

fileExists(target_dir) in pipeline checks the given file in workspace, it is not permitted to access the outside.

to do this, the sh or bat in pipeline can help verify if the target directory exists by calling shell command.

res = sh(script: "test -d ${target_dir} && echo '1' || echo '0' ", returnStdout: true).trim()
if(res=='1'){
    echo 'yes'
} else {
    echo 'no'
}

im not sure that that was your question but fileExists() works for directories as well