1

Below is my groovy code snippet

def filePath = '/logs/result.txt'
def file = new File(filePath)
echo "${file.exists()}"

Output :

result file.exists() = false

But the file /logs/result.txt is actually present.

Also, In IntelliJ editor, file.exists() is shown with dotted underline.

  When I hover mouse over the exists() method it says "No candidates Found for method call  file.exists()".
Vijay Kumar R
  • 41
  • 1
  • 1
  • 4
  • `false` means that file doesn't exist or path is incorrect. Replace `def file =` with `File file =` to remove intellij warning. – daggett Oct 11 '22 at 11:38
  • Echo? Are you running in Jenkins? If yes better to use native Jenkins file-steps. – daggett Oct 11 '22 at 11:39
  • https://stackoverflow.com/questions/38534781/check-if-a-file-exists-in-jenkins-pipeline – tim_yates Oct 11 '22 at 15:20

0 Answers0