Topic "How to properly delete remote directory using .NET library"

Author Message
mmedic
[View user's profile]

Joined: 2015-06-27
Posts: 3
Location: USA
I have tried using Session.RemoveFiles with and without a trailing slash but without success. Operation succeeds but the RemovalOptionResult shows 0 removals. I have verified that the directory exists on the remote server. It does contain [] (brackets) in the name. I am not sure if that causes any issues.
Advertisements
KelvinSmith
[View user's profile]

Joined: 2015-07-01
Posts: 2
Location: Leeds, West Yorkshire, UK
Session.RemoveFiles should not remove the directory with the last file.

May you find solution here:
http://winscp.net/eng/docs/library_session_removefiles

Last edited by KelvinSmith on 2015-07-22 06:59; edited 1 time in total
mmedic
[View user's profile]

Joined: 2015-06-27
Posts: 3
Location: USA
I assume you meant to say "Session.RemoveFiles should not remove the directory with [at least one] file [in it]." My directory is indeed empty but once the command is executed it reports that there was no match found.

In any event, how does not remove a directory (empty or not)? I downloaded the source code and created a method RemoveDirectory which calls
Code:
rmdir -- "dir_name"
and that works but the original library does not seem to provide this functionality. I am missing something?
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24530
Location: Prague, Czechia
mmedic wrote:
I have tried using Session.RemoveFiles with and without a trailing slash but without success. Operation succeeds but the RemovalOptionResult shows 0 removals. I have verified that the directory exists on the remote server. It does contain [] (brackets) in the name. I am not sure if that causes any issues.

Please attach a full session log file showing the problem (using the latest version of WinSCP).

To generate log file, set Session.SessionLogPath. Submit the log with your post as an attachment. Note that passwords and passphrases not stored in the log. You may want to remove other data you consider sensitive though, such as host names, IP addresses, account names or file names (unless they are relevant to the problem). If you do not want to post the log publicly, you can mark the attachment as private.
mmedic
[View user's profile]

Joined: 2015-06-27
Posts: 3
Location: USA
Issue seems to be related to directories that start with '['. If I remove that the remove works. Log attached.
winscp.session.log (8.57 KB) [Download]

Description: (none)

martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24530
Location: Prague, Czechia
Indeed the square bracket [ has a special meaning in the file mask:
http://winscp.net/eng/docs/file_mask#basic

In scripting you have to escape it like:
rm -- "/C:/Shares/Temp/[[]2015] Test"

In .NET assembly, you can (should) use Session.EscapeFileMask method:
http://winscp.net/eng/docs/library_session_escapefilemask
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