コード例 #1
0
    private void DirectPick()
    {
        if (DirectItems.Values.Count <= 0)
        {
            DllBox.MessageBox(IntPtr.Zero, "没东西执行毛线!", "XXX", 0);
            return;
        }
        text.text = "开始执行";
        foreach (GameObject obj in DirectItems.Values)
        {
            DataItem data = obj.GetComponent <ItemScript>().Data;


            string[] baseNames   = Directory.GetFiles(data.BaseDirPath);
            string[] targetNames = Directory.GetFiles(data.TargetDirPath);

            if (!Directory.Exists(LogPath))
            {
                Directory.CreateDirectory(LogPath);
            }
            FileStream   fs = new FileStream(LogPath + data.id + ".txt", FileMode.Append);
            StreamWriter sw = new StreamWriter(fs);
            sw.WriteLine(DateTime.Now);
            sw.WriteLine("源目录" + data.BaseDirPath);
            sw.WriteLine("目标目录" + data.TargetDirPath);
            sw.WriteLine("索引目录" + data.FolderPath);
            sw.WriteLine("索引文件" + data.TxtPath);
            sw.WriteLine("移动张数" + data.Number);
            int count = 0;
            for (int j = 0; j < baseNames.Length; j++)
            {
                Debug.Log(targetNames);
                Debug.Log(data.TargetDirPath + baseNames[j].Replace(data.BaseDirPath, ""));

                if (targetNames.Contains(data.TargetDirPath + baseNames[j].Replace(data.BaseDirPath, "")))
                {
                    sw.WriteLine("跳过文件" + baseNames[j] + "目标已存在");
                    continue;
                }
                count++;
                if (count > data.Number)
                {
                    break;
                }
                try
                {
                    File.Copy(baseNames[j], data.TargetDirPath + baseNames[j].Replace(data.BaseDirPath, ""), true);
                    sw.WriteLine("根据" + baseNames[j] + "成功复制文件" + baseNames[j] + "到" + data.TargetDirPath);
                }
                catch
                {
                    sw.WriteLine("复制失败了" + baseNames[j]);
                }
            }

            sw.Close();
            fs.Close();
        }
        text.text = "执行完毕";
    }
コード例 #2
0
 private bool checkDataError()
 {
     if (data.id == 0)
     {
         DllBox.MessageBox(IntPtr.Zero, "为什么会没有ID,世界人民都震惊了!!!", "异常", 0);
         return(true);
     }
     return(false);
 }
コード例 #3
0
 private bool modeCheck()
 {
     if (mode == Mode.NON)
     {
         DllBox.MessageBox(IntPtr.Zero, "先选模式,臭嫑脸!~", "你干嘛", 0);
         return(true);
     }
     return(false);
 }
コード例 #4
0
    public void setNumber(string content)
    {
        Debug.Log(content);
        if (checkDataError())
        {
            return;
        }
        int i;

        if (int.TryParse(content, out i))
        {
            data.Number = i;
        }
        else
        {
            DllBox.MessageBox(IntPtr.Zero, "填正数", "佩奇", 0);
        }
    }
コード例 #5
0
    private IEnumerator  FolderPick()
    {
        if (FolderItems.Values.Count <= 0)
        {
            DllBox.MessageBox(IntPtr.Zero, "没东西执行毛线!", "XXX", 0);
            yield return(null);
        }
        yield return(null);

        text.text = "开始执行";
        foreach (GameObject obj in FolderItems.Values)
        {
            DataItem data = obj.GetComponent <ItemScript>().Data;

            if (!Directory.Exists(data.BaseDirPath) || !Directory.Exists(data.TargetDirPath) ||
                !Directory.Exists(data.FolderPath))
            {
                continue;
            }


            string[] baseNames   = Directory.GetFiles(data.BaseDirPath);
            string[] targetNames = Directory.GetFiles(data.TargetDirPath);
            string[] FolderNames = Directory.GetFiles(data.FolderPath);


            if (!Directory.Exists(LogPath))
            {
                Directory.CreateDirectory(LogPath);
            }
            FileStream   fs = new FileStream(LogPath + data.id + ".txt", FileMode.Append);
            StreamWriter sw = new StreamWriter(fs);
            sw.WriteLine(DateTime.Now);
            sw.WriteLine("源目录" + data.BaseDirPath);
            sw.WriteLine("目标目录" + data.TargetDirPath);
            sw.WriteLine("索引目录" + data.FolderPath);
            sw.WriteLine("索引文件" + data.TxtPath);
            sw.WriteLine("移动张数" + data.Number);
            int count = 0;

            for (int i = 0; i < FolderNames.Length; i++)
            {
                if (targetNames.Contains(data.TargetDirPath + FolderNames[i].Replace(data.FolderPath, "")))
                {
                    sw.WriteLine("跳过文件" + FolderNames[i] + "目标已存在");
                    continue;
                }
                count++;
                if (count > data.Number)
                {
                    break;
                }
                bool copy = false;

                for (int j = 0; j < baseNames.Length; j++)
                {
                    if (baseNames[j].Equals(data.BaseDirPath + FolderNames[i].Replace(data.FolderPath, "")))
                    {
                        copy = true;
                        try
                        {
                            File.Copy(baseNames[j], data.TargetDirPath + baseNames[j].Replace(data.BaseDirPath, ""), false);
                            sw.WriteLine("根据" + FolderNames[i] + "成功复制文件" + baseNames[j] + "到" + data.TargetDirPath);
                            text.text = "根据" + FolderNames[i] + "成功复制文件" + baseNames[j] + "到" + data.TargetDirPath;
                        }
                        catch
                        {
                            sw.WriteLine("复制失败了" + baseNames[j]);
                            text.text = "复制失败了" + baseNames[j];
                            copy      = false;
                        }
                        yield return(new WaitForSeconds(0.05f));
                    }
                }
                if (!copy)
                {
                    sw.WriteLine("失败了,没找到或不成功" + FolderNames[i]);
                }
            }
            sw.Close();
            fs.Close();
        }
        text.text = "执行完毕";
        Debug.Log("running");

        StopCoroutine("FolderPick");
    }
コード例 #6
0
    private IEnumerator TxtPick()
    {
        if (TxtItems.Values.Count <= 0)
        {
            DllBox.MessageBox(IntPtr.Zero, "没东西执行毛线!", "XXX", 0);
            yield return(null);
        }

        text.text = "开始执行";
        foreach (GameObject obj in TxtItems.Values)
        {
            DataItem data = obj.GetComponent <ItemScript>().Data;

            if (!Directory.Exists(data.BaseDirPath) || !Directory.Exists(data.TargetDirPath) ||
                !File.Exists(data.TxtPath))
            {
                continue;
            }


            string[] baseNames   = Directory.GetFiles(data.BaseDirPath);
            string[] targetNames = Directory.GetFiles(data.TargetDirPath);

            FileStream     txtfs    = new FileStream(data.TxtPath, FileMode.Open);
            StreamReader   sr       = new StreamReader(txtfs);
            Queue <string> txtNames = new Queue <string>();

            for (int c = 0; ; c++)
            {
                string s = sr.ReadLine();
                txtNames.Enqueue(s.Split('#')[0]);
                if (sr.EndOfStream)
                {
                    break;
                }
            }
            sr.Close();
            txtfs.Close();
            Debug.Log("zhixinglema " + txtNames.Count + "123");
            if (!Directory.Exists(LogPath))
            {
                Directory.CreateDirectory(LogPath);
            }
            FileStream   fs = new FileStream(LogPath + data.id + ".txt", FileMode.Append);
            StreamWriter sw = new StreamWriter(fs);
            sw.WriteLine(DateTime.Now);
            sw.WriteLine("源目录" + data.BaseDirPath);
            sw.WriteLine("目标目录" + data.TargetDirPath);
            sw.WriteLine("索引目录" + data.FolderPath);
            sw.WriteLine("索引文件" + data.TxtPath);
            sw.WriteLine("移动张数" + data.Number);
            int count = 0;

            while (txtNames.Count > 0)
            {
                string txtname = txtNames.Dequeue();

                if (targetNames.Contains(data.TargetDirPath + "\\" + txtname))
                {
                    sw.WriteLine("跳过文件" + txtname + "目标已存在");
                    continue;
                }
                count++;
                if (count > data.Number)
                {
                    break;
                }
                bool copy = false;

                for (int j = 0; j < baseNames.Length; j++)
                {
                    if (baseNames[j].Equals(data.BaseDirPath + "\\" + txtname))
                    {
                        copy = true;
                        try
                        {
                            File.Copy(baseNames[j], data.TargetDirPath + baseNames[j].Replace(data.BaseDirPath, ""), false);
                            sw.WriteLine("根据" + txtname + "成功复制文件" + baseNames[j] + "到" + data.TargetDirPath);
                            text.text = "根据" + txtname + "成功复制文件" + baseNames[j] + "到" + data.TargetDirPath + "移动了" + count + "张";
                        }
                        catch
                        {
                            sw.WriteLine("复制失败了" + baseNames[j]);
                            text.text = "复制失败了" + baseNames[j];
                            copy      = false;
                        }
                        yield return(new WaitForSeconds(0.05f));
                    }
                }
                if (!copy)
                {
                    sw.WriteLine("失败了,没找到或不成功" + txtname);
                }
            }
            sw.Close();
            fs.Close();
        }
        text.text = "执行完毕";

        StopCoroutine("TxtPick");
    }