I have a large script that will be asking for a download directory and downloading a bunch of files into it. However, when I set the download filename string based on the directory string, they are both overwritten with the full filename string. Here's what I mean:
$dldir = 'c:\downloads'
$dlfile = $dldir += '\data.csv'
This results in both $dldir and $dlfile to be set to "c:\downloads\data.csv". Obviously, since I want to reuse $dldir to set $dlfile multiple times in the script, I don't want it to change. Does anyone know how to do this?
Thanks.
Instead of:
use:
Another option would be to use Join-Path
The benefit of Join-Path is that you don't have to worry about leading or trailing slashes.. the command will clean that up for you and give you a nice clean file path.
So
or
or
would all turn out with a valid path. This is very useful if you are taking user input for the file location and don't want to worry about sanitizing the input for trailing slashes.