System.IO.DirectoryInfo.MoveTo C# (CSharp) Method

MoveTo() private method

private MoveTo ( String destDirName ) : void
destDirName String
return void
        public void MoveTo(String destDirName)
        {
            if (destDirName == null)
                throw new ArgumentNullException(nameof(destDirName));
            if (destDirName.Length == 0)
                throw new ArgumentException(SR.Argument_EmptyFileName, nameof(destDirName));
            Contract.EndContractBlock();

            String fullDestDirName = Path.GetFullPath(destDirName);
            if (fullDestDirName[fullDestDirName.Length - 1] != Path.DirectorySeparatorChar)
                fullDestDirName = fullDestDirName + PathHelpers.DirectorySeparatorCharAsString;

            String fullSourcePath;
            if (FullPath.Length > 0 && FullPath[FullPath.Length - 1] == Path.DirectorySeparatorChar)
                fullSourcePath = FullPath;
            else
                fullSourcePath = FullPath + PathHelpers.DirectorySeparatorCharAsString;

            if (PathInternal.IsDirectoryTooLong(fullSourcePath))
                throw new PathTooLongException(SR.IO_PathTooLong);

            if (PathInternal.IsDirectoryTooLong(fullDestDirName))
                throw new PathTooLongException(SR.IO_PathTooLong);

            StringComparison pathComparison = PathInternal.StringComparison;
            if (String.Equals(fullSourcePath, fullDestDirName, pathComparison))
                throw new IOException(SR.IO_SourceDestMustBeDifferent);

            String sourceRoot = Path.GetPathRoot(fullSourcePath);
            String destinationRoot = Path.GetPathRoot(fullDestDirName);

            if (!String.Equals(sourceRoot, destinationRoot, pathComparison))
                throw new IOException(SR.IO_SourceDestMustHaveSameRoot);

            FileSystem.Current.MoveDirectory(FullPath, fullDestDirName);

            FullPath = fullDestDirName;
            OriginalPath = destDirName;
            DisplayPath = GetDisplayName(OriginalPath);

            // Flush any cached information about the directory.
            Invalidate();
        }

Same methods

DirectoryInfo::MoveTo ( string destDirName ) : void

Usage Example

Example #1
0
        }//method

        public void DownloadFun(object o)
        {
            while (_avs.Count > 0)
            {
                Av a;
                try
                {
                    a = _avs.Dequeue();
                }
                catch (InvalidOperationException e) {
                    return;
                }

                string url  = basePath + "/" + a.Id;
                string html = "";
                try
                {
                    html = Download.GetHtml(url);
                }
                catch (Exception e)
                {
                    _syncContext.Post(OutError, a.Id + " :查询网站异常");
                    continue;
                }
                if (html.IndexOf("404 Page Not Found") != -1)
                {
                    _syncContext.Post(OutError, a.Id + " :找不到该番号");
                }
                else
                {
                    int    fg   = a.Path.LastIndexOf("\\") + 1;
                    string name = a.Path.Substring(fg, a.Path.Length - fg).Trim();
                    System.IO.DirectoryInfo folder = new System.IO.DirectoryInfo(a.Path);

                    if (!Directory.Exists(a.ToPath + "\\" + a.Id))
                    {
                        Directory.CreateDirectory(a.ToPath + "\\" + a.Id);
                    }
                    if (a.Oname.IndexOf("-cd") != -1)
                    {
                        folder.MoveTo(a.ToPath + "\\" + a.Id + "\\" + a.Oname);
                    }
                    else
                    {
                        if (File.Exists(a.ToPath + "\\" + a.Id + "\\" + name))
                        {
                            _syncContext.Post(OutLog, a.Path + "出现重复!!!!!!!!!!" + a.Id + "");
                        }
                        else
                        {
                            folder.MoveTo(a.ToPath + "\\" + a.Id + "\\" + name);
                            File.Create(a.ToPath + "\\" + a.Id + "\\" + folder.Name + ".old.name").Close();
                        }
                    }
                    _syncContext.Post(OutLog, a.Id + "");
                }
            } //while
            _syncContext.Post(OutLog, "线程退出");
        }     //method
All Usage Examples Of System.IO.DirectoryInfo::MoveTo