Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4096566
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T20:03:46+00:00 2026-05-20T20:03:46+00:00

Background: I’m developing a WinForms application using C# with an OpenFileDialog & FileBrowserDialog that

  • 0

Background: I’m developing a WinForms application using C# with an OpenFileDialog & FileBrowserDialog that will 1) search for a specific string in the filenames of a specified source directory 2) copy files to consolidated directory 3) convert multiple files from excel to csv files, and then 3) convert all the generated csv files into 1 big csv file using a command line executable

Example: MSDN provides a code example that lists all of the directories and files that begin with the letter “c” in “c:\”. at http://msdn.microsoft.com/en-us/library/ms143448.aspx so I based my code on that…

Problem: The code doesn’t copy any files to the consolidated folder so I’m pretty sure the search doesn’t work.

What should I change on here? It doesn’t work :

    string files = "*.xlsx";
    void DirSearch(string sDir)
    {
        try
        {
            foreach (string d in Directory.GetDirectories(sDir))
            {
                foreach (string f in Directory.GetFiles(d, files))
                {
                    // Is this the file we are looking for?
                    // check excel files for corp name in the filename.
                    if (f.Contains(m_sc.get_Corp()))
                    {
                        // check if thread is cancelled
                        if (m_EventStop.WaitOne(0, true))
                        {
                            // clean-up operations may be placed here
                            // ...

                            // inform main thread that this thread stopped
                            m_EventStopped.Set();

                            return;
                        }
                        else
                        {
                            string path = sDir;
                            string searchPattern = m_sc.get_Corp();

                            // A file has been found in this directory
                            DirectoryInfo di = new DirectoryInfo(path);
                            DirectoryInfo[] directories = di.GetDirectories(searchPattern, SearchOption.TopDirectoryOnly);

                            foreach (FileInfo file in files)
                            {

                              try
                              {
                              // Copy each selected xlsx files into the specified TargetFolder 

                              System.IO.File.Copy(FileName, consolidatedFolder + @"\" + System.IO.Path.GetFileName(FileName));
                              Log("File" + FileName + " has been copied to " + consolidatedFolder + @"\" + System.IO.Path.GetFileName(sourceFileOpenFileDialog.FileName));

                             // Convert each selected XLSX File to CSV Using the command prompt code... 
                              }
                            }
                       }
                  }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T20:03:46+00:00Added an answer on May 20, 2026 at 8:03 pm

    The code you’ve posted does two separate search loops:

    first:

        foreach (string d in Directory.GetDirectories(sDir))
        {
            foreach (string f in Directory.GetFiles(d, files))
            {
                // Is this the file we are looking for?
                // check excel files for corp name in the filename.
                if (f.Contains(m_sc.get_Corp()))
                {
    

    then within that it also does:
    string path = sDir;
    string searchPattern = m_sc.get_Corp();

                            // A file has been found in this directory
                            DirectoryInfo di = new DirectoryInfo(path);
                            DirectoryInfo[] directories = di.GetDirectories(searchPattern, SearchOption.TopDirectoryOnly);
    
                            foreach (FileInfo file in files)
                            {
    

    In the first one you are looking for files matching m_sc.get_Corp();, in the second one you are lookinf for directories…

    In fact… your code (pseudo-code?) makes no sense…

    Try:

    • taking your time
    • tidying up the code yourself
    • if you rewrite it slowly and break this into smaller chunks, you might spot what you are doing wrong.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Background: At my company we are developing a bunch applications that are using the
Background: We're building an application that allows our customers to supply data in a
Background This is only my second PyQt4 project. Developing a Windows app that has
Background: I have a winform application written in VB.NET that uses a WebService to
Background: I have a winforms app written in C# that converts xlsx files to
Background Developing a simple web application (Eclipse + JBoss + Apache Tomcat) to generate
Background: I am new to MVP and just coding my first winform application using
Background: I'm using the (fantastic) Vim plugin python-mode , which includes the pep8 linter.
Background - I am using paramiko to put files on a bunch of remote
Background: I would like to dismiss a modalView that I have presented earlier and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.