Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/333.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# 如何在文件夹中写入选定的checklistboxitems_C# - Fatal编程技术网

C# 如何在文件夹中写入选定的checklistboxitems

C# 如何在文件夹中写入选定的checklistboxitems,c#,C#,我在将选定的复选框项写入文本文件时遇到问题 我有2个或2个以上的源路径,我想将选中的复选框项写入单个源路径 目标因为有许多子文件夹,我无法逐个选择该文件夹包含75个以上的文件夹 所以我想通过选择checklistbox项来编写文件。是否可能,或者是否有其他代码 我用这一行写文件夹 checkedListBoxlastrecored.Text=v[0] 此行仅写入单路径文件夹CheckedListBoxLastRecred.Text 例如,E中有三个子文件夹:\ CheckedListBoxLas

我在将选定的复选框项写入文本文件时遇到问题

我有2个或2个以上的源路径,我想将选中的复选框项写入单个源路径 目标因为有许多子文件夹,我无法逐个选择该文件夹包含75个以上的文件夹 所以我想通过选择checklistbox项来编写文件。是否可能,或者是否有其他代码

我用这一行写文件夹

checkedListBoxlastrecored.Text=v[0]

此行仅写入单路径文件夹CheckedListBoxLastRecred.Text

例如,E中有三个子文件夹:\

CheckedListBoxLastRecorded.Text=v[0];\此行仅写入单个选定路径

E:\amex\a-l\这是正在工作的单一路径 E:\amex\dead E:\amex\m-z


提前感谢

听起来好像您正试图将文件名列表放在CheckedListBox中,并且希望此列表递归地包含指定目录及其所有子目录中的所有文件。如果是这种情况,则此代码将执行以下操作:

    private void getFilesButton_Click(object sender, EventArgs e)
    {
        filesCheckedListBox.Items.Clear();
        PopulateWithFilesRecursively(directoryTextBox.Text, filesCheckedListBox, string.Empty);
    }

    private static void PopulateWithFilesRecursively(string sourceDirectory, CheckedListBox checkedListBox, string relativeDirectory)
    {
        foreach (string file in Directory.GetFiles(sourceDirectory))
        {
            checkedListBox.Items.Add(Path.Combine(relativeDirectory, Path.GetFileName(file)));
        }

        foreach (string directory in Directory.GetDirectories(sourceDirectory))
        {
            PopulateWithFilesRecursively(directory, checkedListBox, Path.Combine(relativeDirectory, Path.GetFileName(directory)));
        }
    }