Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/304.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
C# System.IO.Path不包含GetFiles的定义_C#_String_File_Text Files_.net - Fatal编程技术网

C# System.IO.Path不包含GetFiles的定义

C# System.IO.Path不包含GetFiles的定义,c#,string,file,text-files,.net,C#,String,File,Text Files,.net,我有一个奇怪的错误。我有一个两行的文本文件。1具有目录路径,1用于数据 应用程序将给定目录中文件的所有路径写入文本文件。但我希望能够通过第二个文本文件更改路径 以下是读取文本文件的代码: //Reads 2 lines of the text file string[] TextData = File.ReadAllLines(@text file); string DirectoryPath = TextData[1]; string ScanHours = TextData[

我有一个奇怪的错误。我有一个两行的文本文件。1具有目录路径,1用于数据

应用程序将给定目录中文件的所有路径写入文本文件。但我希望能够通过第二个文本文件更改路径

以下是读取文本文件的代码:

//Reads 2 lines of the text file
string[] TextData = File.ReadAllLines(@text file);
    string DirectoryPath = TextData[1];
    string ScanHours = TextData[2];
下面是编写字符串DirectoryPath=TextData[1]的所有文件的代码;发现:

基本上,字符串DirectoryPath=TextData[1];指文本文件中的一行。该行包含指向目录的路径

我得到这个错误:System.IO.Directory不包含GetFiles的定义。 我尝试了多种方法,例如更改Directory.GetFileS;到Path.GetFiles

如果有人能帮助我,或者给我指出正确的方向,我将不胜感激

编辑->完整的代码

其中有一个FileStream/Streamwriter来记录每个输出。但是我把它拿走了

使用Directory.GetFiles而不是Path.GetFiles时编辑2->

System.ArgumentException:路径的格式无效。 在System.IO.Path.NormalizePathString路径中,使用布尔fullCheck,Int32 maxPathLength

位于System.IO.Path.GetFullPathInternalString路径

在System.IO.FileSystemMemerableTerator1..ctorString路径、String originalUserPath、String searchPattern、SearchOption SearchOption、SearchResultHandler1 resultHandler、Boolean checkHost

位于System.IO.Directory.getfilestring路径、String searchPattern、SearchOption SearchOption


在c:\Users\Vvandereng\Documents\Stage\Programmeren\LastWriteAccess Checker\LastWriteAccess Checker\Program.cs:regel 30中的CheckWithinTime.Program.MainString[]参数处,尝试从DirectoryPath值中删除行尾字符

我得到这个错误:System.IO.Directory不包含GetFiles的定义

这是令人困惑的,这里显示了错误

错误1“System.IO.Path”不包含“GetFiles”的定义

使用Directory.GetFiles尝试以下操作


你确定目录是System.IO.Directory吗?看看这个错误,我想你有自己的类System.IO.Directory,如果我发布完整的代码会有帮助吗?好的,大部分相关部分。如果你创建了一个小型但完整的控制台应用程序来重现这个问题,这将是一个很大的帮助。发布前验证。此返回的内容:Console.WriteLineAssembly.GetAssemblytypeofDirectory.CodeBase;我明白你的意思了。但这正是我开始使用的代码,没有任何更改。您的代码使用Path.GetFiles。If Directory.GetFiles也会导致相同的错误,请使用该错误和完整的错误消息,而不是说相同的错误消息。当然错误信息会有所不同,这将帮助我们解决问题哦,糟糕,你是对的,对不起。我添加了使用Directory.GetFiles.DirectoryPath变量时出现的错误。该变量的参数无效或路径无效。检查一下。它应该能解决问题我仔细检查了一下,所有的东西都连接正确了。我不想听起来粗鲁什么的,我感谢你的帮助!但我认为这与string[]TextData有关。
//Writes all the files of DirectoryPath into a string
string[] files = Directory.GetFiles(DirectoryPath, "*.*", System.IO.SearchOption.AllDirectories);
public static void Main(string[] args)
        {
            string[] TextData = File.ReadAllLines(@"C:\TextData.txt");
            string DirectoryPath = TextData[1];
            //string ScanHours = TextData[2];

        //Original
        //string DirectoryPath = File.ReadAllText(@"C:\DirectoryPath.txt");

        string[] files = Path.GetFiles(DirectoryPath, "*.*", System.IO.SearchOption.AllDirectories);
        List<string> updatedFiles = new List<string>();

        DateTime from = DateTime.Now.AddDays(-1);
        DateTime to = DateTime.Now;

        foreach (string name in files)
        {
            FileInfo file = new FileInfo(name);
            string fullname = file.FullName;

            if (file.LastWriteTime >= from && file.LastWriteTime <= to)
            {
                updatedFiles.Add(name);

                Console.WriteLine(file.FullName + " ; " + "last changed at >>  " + " ; " + file.LastWriteTime.ToString());
                Console.WriteLine();
            }

            else
            {

            }
        }
    }
string[] files = Directory.GetFiles(DirectoryPath, "*.*", System.IO.SearchOption.AllDirectories);