美文网首页
将某个文件夹下的所有文件移动到目标文件当中

将某个文件夹下的所有文件移动到目标文件当中

作者: 王一1 | 来源:发表于2018-04-27 15:56 被阅读0次

// 将某个文件夹下的所有文件移动到目标文件当中

    public void MoveFileToDestination(string sourthPath,string destinationPath)

    {

        // 获取源文件夹

        DirectoryInfo sourceFile = new DirectoryInfo(sourthPath);

        // 获取源文件下的所有文件信息

        FileInfo[] fileArray = sourceFile.GetFiles();

        // 遍历每一个文件,将其移动到沙盒

        foreach (FileInfo temp in fileArray)

        {

            // 根据文件名创建目标路径

            string path = Path.Combine(destinationPath, temp.Name);

            // 移动

            temp.MoveTo(path);

        }

    }

相关文章

网友评论

      本文标题:将某个文件夹下的所有文件移动到目标文件当中

      本文链接:https://www.haomeiwen.com/subject/iutilftx.html