I'm trying to write some code for my Jenkins library. I've written the following lines:
steps.println 'Destination Path = ' + target_path
def file = new File(target_path)
steps.println 'target file name: ' + file.getName()
def folder = file.getAbsoluteFile().getParentFile()
steps.println 'target file path: ' + folder.getName()
folder.mkdirs()
But when this code gets executed, I am getting these results
Destination Path = files/docs/My File Name.pdf
[Pipeline] echo
target file name: My File Name.pdf
[Pipeline] echo
target file path: docs
Everything I've found says that getParentFile() is supposed to return ALL the path except the last part (the file name), but it is clearly not doing it in this case. Its just returning the next file up.
I'm also seeing, but is not represented in this code sample, that the getAbsoluteFile() method is simply tacking a slash in front of the whole path. Since this is running under Jenkins, I know that there should at least be a workspace path in front of it, yet I'm not getting any of that.
I thought maybe the spaces in the filename were a problem, but even when I tried without spaces I got the same result.
Can someone please help me with what I'm doing wrong or what I've missed?