发出更新使用string.count显示的文件数 [英] Issue updating number of files displayed using string.count

查看:51
本文介绍了发出更新使用string.count显示的文件数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有合并单词的程序。 doc文件通过用户输入一起。一旦用户选择输入文件夹和输出目的地,就会合并文档并显示合并的文件总数。这是代码的一个例子。

I currently have program that merges word. doc files together via user input. Once the user chooses an input folder and output destination, the documents are combined and the total number of files merged is displayed. here is an example of the code.

MessageBox.Show("A total of " + sourceFiles.Count() + " documents have been merged", 
"Success", MessageBoxButtons.OK, MessageBoxIcon.Information);



程序和string.count目前工作正常,但我遇到的问题是当我更新输入文件夹的内容或选择输出文件夹与中的相同时程序运行时的输入文件夹



例如:如果我选择所需的输入和输出文件夹并成功运行程序,一旦创建了新文件,用户最终会收到一个消息框,上面写着共有X个文件已合并。



如果我拖动另一个文件进入Input文件夹和im中间再次按下合并按钮,X文档合并总数将保持不变,即使已将另一个文件插入该文件夹。程序将继续生成组合文件,但string.count total无法识别新添加的文档。好像程序没有更新文件夹的总内容



sourceFiles被声明为


The program and string.count work perfectly at the moment, however the issue I have is when I update the input folder's contents or choose to the output folder to be the same as in the input folder whilst the program is running

For Example: If I choose the input and output folders desired and run the program successfully, the user will eventually be greeted with a message box saying "a total of X documents have been merged" once the new file has been created.

If I drag an another file into the Input folder and immediately press the 'merge' button again, the "X documents merged" total will remain the same, even though an additional file has been inserted into that folder. The program will continue to make the combined files however the string.count total doesn't recognise the newly added documents. It's as if the program doesn't update folder's total contents

sourceFiles is declared as a

private string [] 

并在用户使用文件夹浏览器对话框选择所需文件夹时调用。

and is called when the user selects their desired folder using a folder browser dialog.

private void browseButton_Click(object sender, EventArgs e)
    {
        FolderBrowserDialog diagBrowser = new FolderBrowserDialog();
        diagBrowser.Description = "Select a folder which contains files needing combined...";

        // Default folder, altered when the user selects folder of choice 
        string selectedFolder = "";
        diagBrowser.SelectedPath = selectedFolder;

        // initial file path display
        folderPath.Text = diagBrowser.SelectedPath;

        // 'OK' button being confirmed on the popup menu
        if (DialogResult.OK == diagBrowser.ShowDialog())
        {
            // Grab the folder that was chosen
            selectedFolder = diagBrowser.SelectedPath;
            folderPath.Text = diagBrowser.SelectedPath;
            sourceFiles = Directory.GetFiles(selectedFolder, "*.doc"); 
  }





然后调用merge命令,合并sourceFiles(文件夹中的文档总数),输出文件名,包括文件之间的日期/时间和分页符



The merge command is then called, combining the sourceFiles (total number of documents in the folder), the output file name which includes a date / time and page break between the files

MsWord.Merge(sourceFiles, outputFileName, pageBreaker);



有任何修改此问题的建议吗?这是一个小小的不便,但我很想得到它



我尝试过:



当用户选择合并按钮而不是选择输入按钮时调用sourceFiles


Any suggestions to amend this issue? It is a small inconvenience however I would love to get it addressed

What I have tried:

Calling the sourceFiles when the user selects the merge button as opposed to when they select their input button

推荐答案

您的 sourceFiles 数组不会因为您向 selectedFolder 添加新文件而更新。开始合并时需要获取 sourceFiles 数组。

所以移动
Your sourceFiles array will not be updated just because you added a new file to the selectedFolder. You need to get the sourceFiles array when you start the merge.
So move the
sourceFiles = Directory.GetFiles(selectedFolder, "*.doc");

将合并按钮处理程序。



你似乎表明你试过这个。发生了什么?没发生?

to be in the merge button handler.

You seem to indicate that you tried this. What happened? didn't happen?


这篇关于发出更新使用string.count显示的文件数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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