Reputation: 439
In a powershell script, how do I use a common file path.
For ex:
$file_path=c:\users\documents
Under documents, I need to operate on 2 folders - "updates" and "archives"
In the script, how do I browse to updates, archives?
I tried $file_path\updates. But that didn't work.
Example, copying a file:
copy c:\users\documents\new_file.txt c:\users\documents\updates
Instead of the full path, I would like to use
copy $file_path\new_file.txt $file_path\updates\
Upvotes: 0
Views: 159
Reputation: 856
param(
[System.IO.DirectoryInfo]$filePath = "c:\users\documents",
[string[]]$subFolders = @("updates", "archives")
)
Join-Path $filePath -ChildPath $subFolders[0]
Join-Path $filePath -ChildPath $subFolders[1]
[System.IO.Path]::Join($filePath, $subFolders[0])
[System.IO.Path]::Join($filePath, $subFolders[1])
Upvotes: 2