error using move file when folder is empty

Advertisement

andybruner
Joined:
Posts:
7

error using move file when folder is empty

I am using this C# code to move files:
session.MoveFile("/parcs/download/PNB/*.xml", "/parcs/download/PNB/Processed/");
It works fine unless the folder is empty then I get this error.
Message:/parcs/download/PNB/*.xml not found.;
Source:WinSCPnet;
Type:WinSCP.SessionRemoteException;
Base Exception:WinSCP.SessionRemoteException: /parcs/download/PNB/*.xml not found.
at WinSCP.Session.MoveFile(String sourcePath, String targetPath)
at RppGLUpdate.Class1.Main(String[] args).
How do I fix this so that it is okay with an empty folder?
THanks.

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
34,943
Location:
Prague, Czechia

Re: error using move file when folder is empty

The Session.MoveFile can move a single file only. Indeed, it works with a file mask, but that was never intended and is a kind of a bug. If you want to use a file mask, you should use Session.EnumerateRemoteFiles and use Session.MoveFile for each found file.
https://winscp.net/eng/docs/library_session_enumerateremotefiles

Reply with quote

andybruner
Joined:
Posts:
7

I see examples like this one where you get the count but when I type in .Count it is not accepted as good code. How do you make it so that .Count shows up as an option? (see attached image) This may sound like an elementary question but I am not a professional programmer. Just trying to piece things together. Thanks.
int directoriesCount = session.EnumerateRemoteFiles(
    sftpFolder, "*.xml", EnumerationOptions.None).Count;

code.jpg

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
34,943
Location:
Prague, Czechia

There's no .Count. There's .Count() extension method. For that you need:
using System.Linq;

Reply with quote

Advertisement

You can post new topics in this forum