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

Thanks for sharing this!
LordRegent

Here's a PowerShell script that can be run via Task Scheduler to set a WinSCP session's Local Startup Directory to reference the current year and month. It's equally easy to run this once a month or several times a day, using the Triggers settings in Task Scheduler.

$newPath="D:\outgoing & Incoming Files\xyz\xyz SETTLEMENT FILES\$(Get-Date -format "yyyy\\MMM")"

$regValue=[uri]::EscapeDataString($newPath)
Set-ItemProperty -Path 'HKCU:\\Software\Martin Prikryl\WinSCP 2\Sessions\xyz@192.168.13.185\' -Name LocalDirectory -Type String -Value $regValue


You should Google for a recent guide to the full list of tokens allowed by the "format" parameter; some examples are at https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/get-date, but beware: significant omissions from that list are "MMM" for the short Month Name and "ddd" for the short Day Name (for those that know them, "format" uses the list M$ popularized with VB and their other Scripting products.)

However, if you're more comfortable with the Unix date formatting tokens, use the "uFormat" parameter instead; see https://ss64.com/bash/date.html#format for details on that list of tokens.

The code is broken up into several commands to enhance understanding and simplify maintenance, but it's technically possible to make this into a one-liner.

A good enhancement would be to move the Session Name into a variable, which would limit maintenance updates to the topmost portion of the script's code; this would also ease copying the script for use with another Session and Folder.
Axum

This is the path I change it and made it prepare for scheduler.But only works for one month.I have set up 12 Powershell batches which is not good as an IT professional and that is why I did not replay you on time.This is the path any way and thank you.

Set-ItemProperty -Path 'Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Software\Martin Prikryl\WinSCP 2\Sessions\xyz@192.168.13.185\' -name LocalDirectory -value "D:%5Coutgoing%20&%20Incoming%20Files%5Cxyz%5Cxyz%20SETTLEMENT%20FILES%5C2014%5CAug"
martin

Would you mind sharing your script?
Axum

I did it using Powershell tool.I thank you very much.
Axum

Thank you for your time and valuable information.
Will you give me a sample script after I try to do it myself?
martin

Well, you can write a script that changes respective Windows Registry key to modify the path automatically as you need:

[HKEY_CURRENT_USER\Software\Martin Prikryl\WinSCP 2\Sessions\<session_name>]

"LocalDirectory"="<path>"
Guest

Thank you for your quick response.
My question is I want to change the local directory path of winscp and hold it as default automatically in every month like Local Directory path January with January month, February with February month, March with March month etc.This can be done using GUI environment by changing in Local Directory every month and hold it that directory for one month then I change to anther month when the other month comes etc but I want to do it automatically like using script or others without manually.
Sorry for my English.
martin

Re: Local Directry Change and hold it every month

I'm not sure if I understand. Do you want WinSCP to automatically change its GUI startup directory using some pattern (like C:\files_%MONTH%)?
Axum

Local Directry Change and hold it every month

How to change local directory of WinScp every month automatically?I know I can change every month using WinScp GUI.I did not register when I posted as a Guest;sorry for the duplication.
If you help me,I say thank you very much because all I have got is only gratitude.