Using .NET assembly to remove folder

Advertisement

ramc10
Joined:
Posts:
1

Using .NET assembly to remove folder

Hi,
I have an SFTP site were files are delivered in a folder, were the folder name would be the previous day date. If it's 8th October the folder would be 20201007. After that the files are downloaded, I need to remove the folder with all of its contents.

I configured the below variables in the script
$yesterday = (Get-date).AddDays(-1)
$timestamp = $yesterday.ToString("yyyyMMdd")
Then I'm trying to remove the folder using the below command
Session.RemoveFile(RemotePath.EscapeFileMask(/folder/$timestamp))
I'm being prompted /folder/$timestamp isn't recognized.

Regards
RamC

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,518
Location:
Prague, Czechia

Re: using .NetAssembly to remove folder

Because that's not a valid PowerShell code. It looks more like C#, but it's not valid C# either.
Also with Session.RemoveFile, do not use RemotePath.EscapeFileMask.

It should be like:
$session.RemoveFile("/folder/$timestamp")
(assuming you have $session variable with an instance of Session class)

Reply with quote

Advertisement

You can post new topics in this forum