Example #1
0
        protected override void ProcessRecord()
        {
            ProviderInfo  provider;
            PSDriveInfo   drive;
            List <string> Paths = new List <string>();

            if (_path != null)
            {
                foreach (var s in _path)
                {
                    Paths.AddRange(this.GetResolvedProviderPathFromPSPath(s, out provider));
                }
            }

            if (_litpath != null)
            {
                foreach (var s in _litpath)
                {
                    Paths.Add(this.SessionState.Path.GetUnresolvedProviderPathFromPSPath(s, out provider, out drive));
                }
            }


            foreach (string origpath in Paths)
            {
                try
                {
                    FileInfo pO      = new FileInfo(origpath);
                    String   Message = "Delete Item " + origpath;

                    if (!WhatIf)
                    {
                        if (pO.Attributes.HasFlag(System.IO.FileAttributes.Directory))
                        {
                            Directory.Delete(origpath, Recurse, Force);
                        }
                        else
                        {
                            File.Delete(origpath, Force);
                        }
                        if (PassThru)
                        {
                            WriteObject(pO);
                        }
                    }
                    else
                    {
                        Message = "Simulated " + Message;
                        WriteObject(Message);
                    }
                    if (this.LogVariable != null)
                    {
                        VariableLogger.log(this.SessionState, LogVariable, Message);
                    }
                }
                catch (PipelineStoppedException e)
                {
                    return;
                }
            }
        }
Example #2
0
        protected override void ProcessRecord()
        {
            try
            {
                ProviderInfo  provider;
                PSDriveInfo   drive;
                List <string> Paths = new List <string>();

                if (_path != null)
                {
                    foreach (var s in _path)
                    {
                        Paths.AddRange(this.GetResolvedProviderPathFromPSPath(s, out provider));
                    }
                }

                if (_litpath != null)
                {
                    foreach (var s in _litpath)
                    {
                        Paths.Add(this.SessionState.Path.GetUnresolvedProviderPathFromPSPath(s, out provider, out drive));
                    }
                }

                string   dstpath = this.GetUnresolvedProviderPathFromPSPath(Destination);
                FileInfo dstobj  = new FileInfo(dstpath);

                foreach (string origpath in Paths)
                {
                    string tmpdst = dstpath;

                    FileInfo pO = new FileInfo(origpath);
                    if (Directory.Exists(dstpath))
                    {
                        tmpdst = Path.Combine(dstpath, Path.GetFileName(origpath));
                    }
                    string Message = "Move Item " + origpath + " to " + tmpdst;

                    if (!WhatIf)
                    {
                        if (pO.Attributes.HasFlag(System.IO.FileAttributes.Directory))
                        {
                            Directory.Move(origpath, tmpdst, (Force) ? MoveOptions.ReplaceExisting : MoveOptions.None);
                            if (PassThru)
                            {
                                WriteObject(new DirectoryInfo(tmpdst));
                            }
                        }
                        else
                        {
                            File.Move(origpath, tmpdst, (Force) ? MoveOptions.ReplaceExisting : MoveOptions.None);
                            if (PassThru)
                            {
                                WriteObject(new FileInfo(tmpdst));
                            }
                        }
                    }
                    else
                    {
                        Message = "Simulated " + Message;
                        WriteObject(Message);
                    }
                    if (this.LogVariable != null)
                    {
                        VariableLogger.log(this.SessionState, LogVariable, Message);
                    }
                }
            }
            catch (PipelineStoppedException e)
            {
                return;
            }
        }