How can i get the fileinfo of all files in a folder with GetFile()?

后端 未结 2 1745
盖世英雄少女心
盖世英雄少女心 2021-02-07 02:33

I dont know whats my mistake.

FileInfo[] FileInformation = DirectoryInfo.GetFiles(textBoxPath.Text);  
for (int i = 0; i <= FileInformation.Length; i++)
{
            


        
2条回答
  •  你的背包
    2021-02-07 02:48

    Use the following:

        System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(textBoxPath.Text);
        System.IO.FileInfo[] fileInformations = dir.GetFiles();  
        for (int i = 0; i <= fileInformations.Length; i++)
        {
            System.IO.File.Move(fileInformations[i].DirectoryName, System.IO.Path.Combine(FileInformation[i].Directory, "File" + i));
        }
    

    EDIT: renamed your FileInformation to the properway to write local variable names fileInformations. Used Path.Combine to combine paths and filename instead of using string combination, as this will take care of missing / and other path issues.

提交回复
热议问题