In Java I'm used to working with paths as semantic, platform-agnostic Path
objects. If I have a directory dir
and I want to find the filename bar.txt
inside that directory, I'd use something like dir.resolve("bar.txt")
, which would resolve foo.bar
to the parent directory dir
. I would not use dir.toString() + "\bar.txt"
; this would be considered back practice, as it is error-prone and assumes a path separator \
(which might be /
on Linux for example).
In my PowerShell script the user passes an $archive
variable containing some foo.zip
archive. I expand it to foo.zip.tmp
like this:
$dir = $archive + '.tmp'
Expand-Archive -Path $archive -DestinationPath $dir
At this point I want to work with a file bar.txt
inside that new directory—that is, $dir + '\bar.txt'
. But what is the best-practices approach for resolving a known filename to some directory variable in PowerShell? I hope this is not the best we can do, for the reasons explained above:
$barFile = $dir + '\bar.txt'