Prepending date to file during upload in PS script

Advertisement

catmanchampion
Joined:
Posts:
1

Prepending date to file during upload in PS script

Hello, I am fairly new to using winscp and using powershell to script with it. I am working on a script to upload files and was trying to prepend the date to the filename during upload. I was looking at the Operation Mask documentation, but still haven't quite gotten it. Given the code below, I was hoping to transfer two text files "a.txt" and "b.txt" in C:\source to the remote directory /source/withDate with files names "20190523a.txt" "20190523b.txt" respectively. Unfortunately that isn't working and I am getting a directory named with the date instead. Could someone point me in the right direction with the proper operation mask to achieve the date prepending?
$DateStr = Get-Date -format "yyyyMMdd"
 
$session.PutFiles("C:\source", #Source Path
                   "/source/withDate/$DateStr*" #Destination Path,
                ).Check() #Check for any errors in the transfer

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
32,073
Location:
Prague, Czechia

Re: Prepending date to file during upload in PS script

You cannot prepend anything with an operation mask.

You have to iterate the source files and upload them one-by-one, modifying the file name of each file separately.

Check this for a very similar problem:
https://superuser.com/q/1013540/213663

Reply with quote

Advertisement

You can post new topics in this forum