Topic "Powershell .NET Create an Array of files from Remote Dir"

Author Message
jesc516
[View user's profile]

Joined: 2014-12-09
Posts: 5
how would i go about creating an array of files from the remote directory once i am logged in?

this is what i want to do, but on the remote side.

Code:
$YYMD = ((Get-Date).AddDays(-1).ToString("yyyyMMdd"))

$arr = Get-ChildItem | Where-Object { ($_.name -match "ASSIGNMENTS_" + $YYMD + "*") -or ($_.name -match "PAYMENTS_" + $YYMD + "*") }

foreach ($a in $arr)
{
    ### Download files
}


the asterisk is there because that part of file name is a time stamp. the time is random.

would this be the most efficient method or is there a better alternative?

any help is greatly appreciated..
Advertisements
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24530
Location: Prague, Czechia
See http://winscp.net/eng/docs/library_example_listing_files_matching_wildcard
_________________
Martin Prikryl
jesc516
[View user's profile]

Joined: 2014-12-09
Posts: 5


this worked, thank you once again prikryl.

question, is the param() optional? vs defining the variables outside of the try {} statement?
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24530
Location: Prague, Czechia
The param keyword allows overriding the variable value on command-line. Refer to PowerShell manuals.
_________________
Martin Prikryl
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License