Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 使用文本文件中的路径将文件从文件夹移动到另一个文件夹的脚本_Windows_File_Move - Fatal编程技术网

Windows 使用文本文件中的路径将文件从文件夹移动到另一个文件夹的脚本

Windows 使用文本文件中的路径将文件从文件夹移动到另一个文件夹的脚本,windows,file,move,Windows,File,Move,在Windows 8上,是否有人可以帮助我创建一个脚本,将某些图像从特定文件夹移动到另一个文件夹 列出我要移动的图像的文件路径并非文件夹中的所有图像都列在此文件中:C:\Users\Emmanuel\Desktop\test.txt 包含我要删除的某些图像的文件夹将显示在此文件夹中: C:\Users\Computer\Desktop\Images1 我希望将图像移动到的文件夹是以下文件夹: C:\Users\Computer\Desktop\Images2 如果SourcesFile是您的te

在Windows 8上,是否有人可以帮助我创建一个脚本,将某些图像从特定文件夹移动到另一个文件夹

列出我要移动的图像的文件路径并非文件夹中的所有图像都列在此文件中:C:\Users\Emmanuel\Desktop\test.txt

包含我要删除的某些图像的文件夹将显示在此文件夹中:

C:\Users\Computer\Desktop\Images1

我希望将图像移动到的文件夹是以下文件夹:

C:\Users\Computer\Desktop\Images2


如果SourcesFile是您的test.txt,DestFolder是您的目标,我们将非常感谢您的帮助

    public int Run()
    {
        if (!File.Exists(SourcesFile))
        {
            throw new ArgumentException("Source folder does not exist");
        }

        if (!Directory.Exists(DestFolder))
        {
            Console.WriteLine("Destination folder doesn't exist");
            Console.WriteLine("Creating destination folder...");
            Directory.CreateDirectory(DestFolder);
        }

        string[] files = File.ReadAllLines(SourcesFile);
        Console.WriteLine("Moving {0} files...", files.Length);
        foreach (string file in files)
        {
            string dest = Path.Combine(DestFolder, Path.GetFileName(file));
            if (File.Exists(dest))
            {
                string newFilename = string.Format("{0}_{1}{2}",
                    Path.GetFileNameWithoutExtension(file),
                    Guid.NewGuid().ToString("N"),
                    Path.GetExtension(file));

                string newDest = Path.Combine(DestFolder, newFilename);
                Console.WriteLine("File {0} already exists, copying file to {1}", file, newDest);
                File.Move(file, newDest);
                continue;
            }
            File.Move(file, dest);
        }
        return 0;
    }

说明你的操作系统。如果您使用的是Windows,那么XCOPY可能就是您想要的。我使用的是Windows 8: