Delete() public method

public Delete ( string path ) : bool
path string
return bool
Example #1
0
        static void execute(string action, string user, string key, string netstorageURI,
            string uploadfile, string outputfile, string target, string dst, bool indexZip)
        {
            if (action == null || netstorageURI == null || user == null || key == null)
            {
                help();
                return;
            }

            string[] hostpath = netstorageURI.Split("/".ToCharArray(), 2);
            string host = hostpath[0];
            string path = hostpath[1];
            NetStorage ns = new NetStorage(host, user, key);
            Stream result = null;
            bool success = true;

            switch (action)
            {
                case "delete":
                    success = ns.Delete(path);
                    break;
                case "quickdelete":
                    success = ns.QuickDelete(path);
                    break;
                case "dir":
                    result = ns.Dir(path);
                    break;
                case "download":
                    result = ns.Download(path);
                    break;
                case "du":
                    result = ns.DU(path);
                    break;
                case "mkdir":
                    success = ns.MkDir(path);
                    break;
                case "mtime":
                    success = ns.MTime(path);
                    break;
                case "rename":
                    if (dst == null)
                    {
                        help();
                        return;
                    }
                    success = ns.Rename(path, dst);
                    break;
                case "rmdir":
                    success = ns.RmDir(path);
                    break;
                case "stat":
                    result = ns.Stat(path);
                    break;
                case "symlink":
                    if (target == null)
                    {
                        help();
                        return;
                    }
                    success = ns.Symlink(path, target);
                    break;
                case "upload":
                    if (uploadfile == null)
                    {
                        help();
                        return;
                    }
                    success = ns.Upload(path, new FileInfo(uploadfile), indexZip);
                    break;
                default:
                    help();
                    return;
            }

            if (result != null)
            {
                Stream output = Console.OpenStandardOutput();
                if (outputfile != null)
                    output = new FileInfo(outputfile).OpenWrite();

                using (output)
                {
                    using (result)
                    {
                        byte[] buffer = new byte[32*1024];
                        int bytesRead = 0;

                        while ((bytesRead = result.Read(buffer, 0, buffer.Length)) != 0)
                        {
                            output.Write(buffer, 0, bytesRead);
                        }
                    }
                }
            }
            else if (success)
                Console.Out.WriteLine("Success.");
            else
                Console.Error.WriteLine("Error.");
        }