Using Directory.Exists allways give "false"

Advertisement

idan357
Guest

Using Directory.Exists allways give "false"

Hello all,

Im using "Directory.Exists" to verify if a folder exist and if not im crating it.

My problem is the the "Directory.Exists" is always false.
i want to verify "myfolder"
bool FolderExist= Directory.Exists("/folder1/folder2/myfolder");

im using SCP protocol and
session.ExecuteCommand("mkdir /folder1/folder2/myfolder")
to crate it later in the code and it works with no problem.

But still "Directory.Exists" is always false.
What am i missing here ?


BR,
Idan

Reply with quote

Advertisement

idan357
Guest

Re: Using Directory.Exists allways give "false"

idan357 wrote:

Hello all,

Im using "Directory.Exists" to verify if a folder exist and if not im crating it.

My problem is the the "Directory.Exists" is always false.
i want to verify "myfolder"
bool FolderExist= Directory.Exists("/folder1/folder2/myfolder");

im using SCP protocol and
session.ExecuteCommand("mkdir /folder1/folder2/myfolder")
to crate it later in the code and it works with no problem.

But still "Directory.Exists" is always false.
What am i missing here ?


BR,
Idan

Using
RemoteDirectoryInfo info1 = session.ListDirectory("/folder1/folder2/myfolder")
shows the directory info and the number of files under it.

Reply with quote

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

Re: Using Directory.Exists allways give "false"

Who says that Directory.Exists should work for remote paths?

Use Session.FileExists.
https://winscp.net/eng/docs/library_session_fileexists
It works for directories too.

If you want to test for directory explicitly, use Session.GetFileInfo and test RemoteFileInfo.IsDirectory:
https://winscp.net/eng/docs/library_session_getfileinfo
https://winscp.net/eng/docs/library_remotefileinfo

Reply with quote

Advertisement

You can post new topics in this forum