如何将所有输入文件复制到我创建的临时目录中

本文关键字:创建 输入 复制 文件 | 更新日期: 2023-09-27 18:25:31

如何使我创建的临时目录中的所有输入文件可用。只有最后一个文件存在。。我想要从文件开始到结束的所有文件。希望有人能在这里找到我的问题。

下面是我的编码。

var partText = Global.PartText;
            Global.PartText = string.Empty;
            Global.TmpFileCount = 0;
            var tempfile = Global.TempContent;
            Global.TempContent = string.Empty;
            var temp = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Temp");
            if (Directory.Exists(temp))
            {
                Directory.Delete(temp, true);
            }
            Directory.CreateDirectory(temp);
            var content = File.ReadAllText(inputfile);
            tempfile = Path.Combine(temp, string.Concat(Path.GetFileNameWithoutExtension(inputfile), ".html"));
            File.WriteAllText(tempfile, content);
            var text = File.ReadAllText(tempfile);
            text = text.Replace("&", "&");
            File.WriteAllText(tempfile, text);
            Global.TmpFileCount++;
            if (tempfile.Contains("<h1"))
            {
                _chapterName = inputXDoc.XPathSelectElement("//h1").Value;
            }
            else if (tempfile.Contains("<h2"))
            {
                _chapterName = inputXDoc.XPathSelectElement("//h2").Value;
            }
            else if (tempfile.Contains("<h3"))
            {
                _chapterName = inputXDoc.XPathSelectElement("//h3").Value;
            }
            else if (tempfile.Contains("<h4"))
            {
                _chapterName = inputXDoc.XPathSelectElement("//h4").Value;
            }
            //Directory.Delete(temp, true);
            //var source = inputXDoc.Descendants(GetNamespace(ref namespace2, "").GetName("body"));
            //if (source.Descendants(GetNamespace(ref namespace2, "").GetName("div")).Any())
            //{
            //  var introduced5 = inputXDoc.Descendants(GetNamespace(ref namespace2, "").GetName("body"));
            //  if (introduced5.Descendants(GetNamespace(ref namespace2, "").GetName("div")).First().Attributes("id").Any())
            //  {
            //      var introduced6 = inputXDoc.Descendants(GetNamespace(ref namespace2, "").GetName("body"));
            //      _chapterName = introduced6.Descendants(GetNamespace(ref namespace2, "").GetName("div")).First().Attributes("id").First().Value;
            //  }
            //}
            if (Regex.IsMatch(ipName, "cover", RegexOptions.IgnoreCase))
            {
                return "cover";
            }
            if (Regex.IsMatch(ipName, "bibliography", RegexOptions.IgnoreCase))
            {
                return "bibliography";
            }
            if (Regex.IsMatch(ipName, "foreword", RegexOptions.IgnoreCase))
            {
                return "foreword";
            }
            if (Regex.IsMatch(ipName, "toc", RegexOptions.IgnoreCase))
            {
                return "toc";
            }
            if (Regex.IsMatch(ipName, "cop(yright)?", RegexOptions.IgnoreCase))
            {
                return "copyright-page";
            }
            if (Regex.IsMatch(ipName, "halftitlepage", RegexOptions.IgnoreCase))
            {
                return "title-page";
            }
            if (Regex.IsMatch(ipName, "titlepage", RegexOptions.IgnoreCase))
            {
                return "title-page";
            }
            if (Regex.IsMatch(ipName, "ded(ication)?", RegexOptions.IgnoreCase))
            {
                return "dedication";
            }
            if (Regex.IsMatch(ipName, "part", RegexOptions.IgnoreCase))
            {
                Global.PartText = _chapterName;
                return "text";
            }
            Global.PartText = partText;
            const string str = "text";
            Global.FileCount++;

如何将所有输入文件复制到我创建的临时目录中

您每次都在删除目录。更改此项:

        if (Directory.Exists(temp))
        {
            Directory.Delete(temp, true);
        }
        Directory.CreateDirectory(temp);

对此:

        if (!Directory.Exists(temp))
        {
            Directory.CreateDirectory(temp);
        }