相关疑难解决方法(0)

626
推荐指数
10
解决办法
101万
查看次数

如何读取特定文件夹中的所有文件

我想读取c#.net中特定文件夹中的所有xml文件

XDocument doc2 = XDocument.Load((PG.SMNR.XMLDataSourceUtil.GetXMLFilePath(Locale, "Products/category/product.xml")));
Run Code Online (Sandbox Code Playgroud)

我有类别文件夹中的多个产品..想要循环文件夹,并应获取所有产品xml文件名.

XDocument doc2 = XDocument.Load((PG.SMNR.XMLDataSourceUtil.GetXMLFilePath(Locale, "Products/category/x1.xml")));
Run Code Online (Sandbox Code Playgroud)

c# xml file

92
推荐指数
6
解决办法
22万
查看次数

如何读取给定文件夹中的所有文件?

下面的程序解析了一个所谓的Dwarf Fortress的 RAW文件.代码工作正常,但是对于我当前的实现,我需要为每个文件运行一次程序,每次手动更改源文件.有没有我可以改为解析给定文件夹中的所有文本文件?

(请注意,当前输出文件与输入文件位于同一个文件夹中.我不太确定如果程序试图打开文件时会发生什么情况,但是这是有意义的.心神).

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            // create reader & open file
            string filePath = @"C:\foo\Dwarf Fortess\creature_domestic.txt";
            string destPath = @"C:\foo\Dwarf Fortess\eggCreatures.txt";
            string line;
            // 
            TextReader tr = new StreamReader(filePath);
            TextWriter tw = new StreamWriter(destPath);

            // read a line of text
            while ((line = tr.ReadLine()) != null) 
            {

                        if (line.Contains("[CREATURE:"))
                        {
                            tw.WriteLine(line);
                        }
                        if(line.Contains("[LAYS_EGGS]"))
                        {
                            tr.ReadLine();
                            tr.ReadLine();
                            tr.ReadLine(); …
Run Code Online (Sandbox Code Playgroud)

c#

1
推荐指数
1
解决办法
3504
查看次数

标签 统计

c# ×2

file ×2

directory ×1

io ×1

java ×1

xml ×1