Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

martin

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
catmanchampion

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