无法读取xml目录 [英] Trouble reading xml directory

查看:62
本文介绍了无法读取xml目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我正在尝试从xml文件的多个目录中读取并选择要放在一个文件夹中的某些目录。一切顺利,直到我在File.WriteAllText函数中收到错误消息。我验证了写入的目录确实存在。 4cenUs.xml也是第一个被写入目录的文件。



下面是代码

它说:

Hello I am trying to read from multiple directories of xml files and select certain ones to be placed in one folder. Everything goes well until I get an error message at the "File.WriteAllText" function. I verified the directory being written to does exist. 4cenUs.xml is also the first file that is suppose to be written to the directory.

Below is the code
It says:

can not find part of the path at C:\pg\XMLPull\xmlFiles2015\4cenUS.xml

DirectoryInfo di = Directory.CreateDirectory(@"C:\pg\XMLPull\xmlFiles2015\");

var getFiles = Directory.GetFiles(@"\\Company\file\","*xml",SearchOption.AllDirectories).ToList();

            DirectoryInfo di = Directory.CreateDirectory(;C:\pg\XMLPull\xmlFiles2015\);
           getFiles.ForEach(file =>
           {
               var fileContents = File.ReadAllText(file);

               if (!fileContents.Contains(Diagnostics<systemname>))

                   return;
               else

                       File.WriteAllText(C:\pg\XMLPull\xmlFiles52015\ + Path.GetFileName(file), fileContents)
</pre>

推荐答案

else
   File.WriteAllText(@"C:\pg\XMLPull\xmlFiles52015\" + Path.GetFileName(file), fileContents);





有一个拼写错误。您可以将根目录放在字符串const中以避免此类问题。



There is a typo. You could put the root directory in a string const to avoid this kind of problem.


这篇关于无法读取xml目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆