Topic "Using Directory.Exists allways give "false""

Author Message
idan357

Guest


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"
Code:
bool FolderExist= Directory.Exists("/folder1/folder2/myfolder");


im using SCP protocol and
Code:
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
idan357

Guest


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"
Code:
bool FolderExist= Directory.Exists("/folder1/folder2/myfolder");


im using SCP protocol and
Code:
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
Code:
RemoteDirectoryInfo info1 = session.ListDirectory("/folder1/folder2/myfolder")
shows the directory info and the number of files under it.
martin◆
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 26730
Location: Prague, Czechia
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
Advertisements

You can post new topics in this forum

Search

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