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 9205683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:00:29+00:00 2026-06-18T00:00:29+00:00

I am making a tool using c# that iterates through a large file directory

  • 0

I am making a tool using c# that iterates through a large file directory and extracts certain information. The directory is organised by language (LCID), so I want to use multithreading to go through the directory- one thread per language folder.

My code currently scans through a small number of the files and extracts the required data without multithreading, but on a large scale it will take too long.

I set up a thread within my loop that gets the LCID folders, but got the following error: “no overload for ‘HBscan’ matches delegate System.threading.threadstart”. From what I read online, I then put my method within a class so I could have parameters, and now there’s no errors but the code is not iterating through the files properly. It is leaving files out of it’s scan.

I was wondering if anyone could see where I was going wrong with my code that’s making it not perform properly? Thanks.

public static void Main(string[] args)
    {
        //change rootDirectory variable to point to directory which you wish to scan through
        string rootDirectory = @"C:\sample";
        DirectoryInfo dir = new DirectoryInfo(rootDirectory);

        //get the LCIDs from the folders
        string[] filePaths = Directory.GetDirectories(rootDirectory);
        for (int i = 0; i < filePaths.Length; i++)
        {
            string LCID = filePaths[i].Split('\\').Last();
            Console.WriteLine(LCID);

            HBScanner scanner = new HBScanner(new DirectoryInfo(filePaths[i]));
            Thread t1 = new Thread(new ThreadStart(scanner.HBscan));              
            t1.Start();             
        } 

        Console.WriteLine("Scanning through files...");

    }
    public class HBScanner
    {
        private DirectoryInfo DirectoryToScan { get; set; }

        public HBScanner(DirectoryInfo startDir)
        {
            DirectoryToScan = startDir;
        }

        public void HBscan()
        {
            HBscan(DirectoryToScan);
        } 

        public static void HBscan(DirectoryInfo directoryToScan)
        {
            //create an array of files using FileInfo object
            FileInfo[] files;
            //get all files for the current directory
            files = directoryToScan.GetFiles("*.*");
            string asset = "";
            string lcid = "";

            //iterate through the directory and get file details
            foreach (FileInfo file in files)
            {
                String name = file.Name;
                DateTime lastModified = file.LastWriteTime;
                String path = file.FullName;

                //first check the file name for asset id using regular expression
                Regex regEx = new Regex(@"([A-Z][A-Z][0-9]{8,10})\.");
                asset = regEx.Match(file.Name).Groups[1].Value.ToString();

                //get LCID from the file path using regular expression
                Regex LCIDregEx = new Regex(@"sample\\(\d{4,5})");
                lcid = LCIDregEx.Match(file.FullName).Groups[1].Value.ToString();

                //if it can't find it from filename, it looks into xml
                if (file.Extension == ".xml" && asset == "")
                {
                    System.Diagnostics.Debug.WriteLine("File is an .XML");
                    System.Diagnostics.Debug.WriteLine("file.FullName is: " + file.FullName);
                    XmlDocument xmlDoc = new XmlDocument();
                    xmlDoc.Load(path);
                    //load XML file in 

                    //check for <assetid> element
                    XmlNode assetIDNode = xmlDoc.GetElementsByTagName("assetid")[0];
                    //check for <Asset> element
                    XmlNode AssetIdNodeWithAttribute = xmlDoc.GetElementsByTagName("Asset")[0];

                    //if there is an <assetid> element
                    if (assetIDNode != null)
                    {
                        asset = assetIDNode.InnerText;
                    }
                    else if (AssetIdNodeWithAttribute != null) //if there is an <asset> element, see if it has an AssetID attribute
                    {
                        //get the attribute 
                        asset = AssetIdNodeWithAttribute.Attributes["AssetId"].Value;

                        if (AssetIdNodeWithAttribute.Attributes != null)
                        {
                            var attributeTest = AssetIdNodeWithAttribute.Attributes["AssetId"];
                            if (attributeTest != null)
                            {
                                asset = attributeTest.Value;
                            }
                        }
                    }
                }

                Item newFile = new Item
                {
                    AssetID = asset,
                    LCID = lcid,
                    LastModifiedDate = lastModified,
                    Path = path,
                    FileName = name
                };

                Console.WriteLine(newFile);

            }

            //get sub-folders for the current directory
            DirectoryInfo[] dirs = directoryToScan.GetDirectories("*.*");
            foreach (DirectoryInfo dir in dirs)
            {
                HBscan(dir);
            }
        }
    }
  • 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-06-18T00:00:31+00:00Added an answer on June 18, 2026 at 12:00 am

    I havent checked, but i think this could work.

    The code will create one scanner per thread and perform the HBscan method.

    public static void Main(string[] args)
            {
                //change rootDirectory variable to point to directory which you wish to scan through
                string rootDirectory = @"C:\sample";
                DirectoryInfo dir = new DirectoryInfo(rootDirectory);
    
                //get the LCIDs from the folders
                string[] filePaths = Directory.GetDirectories(rootDirectory);
                for (int i = 0; i < filePaths.Length; i++)
                {
                    string LCID = filePaths[i].Split('\\').Last();
                    Console.WriteLine(LCID);
    
                    Thread t1 = new Thread(() => new HBScanner(new DirectoryInfo(filePaths[i])).HBscan());
                    t1.Start();
                }
    
                Console.WriteLine("Scanning through files...");
    
            }
            public class HBScanner
            {
                private DirectoryInfo DirectoryToScan { get; set; }
    
                public HBScanner(DirectoryInfo startDir)
                {
                    DirectoryToScan = startDir;
                }
    
                public void HBscan()
                {
                    HBscan(DirectoryToScan);
                }
    
                public static void HBscan(DirectoryInfo directoryToScan)
                {
                    //create an array of files using FileInfo object
                    FileInfo[] files;
                    //get all files for the current directory
                    files = directoryToScan.GetFiles("*.*");
                    string asset = "";
                    string lcid = "";
    
                    //iterate through the directory and get file details
                    foreach (FileInfo file in files)
                    {
                        String name = file.Name;
                        DateTime lastModified = file.LastWriteTime;
                        String path = file.FullName;
    
                        //first check the file name for asset id using regular expression
                        Regex regEx = new Regex(@"([A-Z][A-Z][0-9]{8,10})\.");
                        asset = regEx.Match(file.Name).Groups[1].Value.ToString();
    
                        //get LCID from the file path using regular expression
                        Regex LCIDregEx = new Regex(@"sample\\(\d{4,5})");
                        lcid = LCIDregEx.Match(file.FullName).Groups[1].Value.ToString();
    
                        //if it can't find it from filename, it looks into xml
                        if (file.Extension == ".xml" && asset == "")
                        {
                            System.Diagnostics.Debug.WriteLine("File is an .XML");
                            System.Diagnostics.Debug.WriteLine("file.FullName is: " + file.FullName);
                            XmlDocument xmlDoc = new XmlDocument();
                            xmlDoc.Load(path);
                            //load XML file in 
    
                            //check for <assetid> element
                            XmlNode assetIDNode = xmlDoc.GetElementsByTagName("assetid")[0];
                            //check for <Asset> element
                            XmlNode AssetIdNodeWithAttribute = xmlDoc.GetElementsByTagName("Asset")[0];
    
                            //if there is an <assetid> element
                            if (assetIDNode != null)
                            {
                                asset = assetIDNode.InnerText;
                            }
                            else if (AssetIdNodeWithAttribute != null) //if there is an <asset> element, see if it has an AssetID attribute
                            {
                                //get the attribute 
                                asset = AssetIdNodeWithAttribute.Attributes["AssetId"].Value;
    
                                if (AssetIdNodeWithAttribute.Attributes != null)
                                {
                                    var attributeTest = AssetIdNodeWithAttribute.Attributes["AssetId"];
                                    if (attributeTest != null)
                                    {
                                        asset = attributeTest.Value;
                                    }
                                }
                            }
                        }
    
                        Item newFile = new Item
                        {
                            AssetID = asset,
                            LCID = lcid,
                            LastModifiedDate = lastModified,
                            Path = path,
                            FileName = name
                        };
    
                        Console.WriteLine(newFile);
    
                    }
    
                    //get sub-folders for the current directory
                    DirectoryInfo[] dirs = directoryToScan.GetDirectories("*.*");
                    foreach (DirectoryInfo dir in dirs)
                    {
                        HBscan(dir);
                    }
                }
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a tool to test a connection to certain host using a class
I'm making a small tool application that user can minimize in the taskbar .
Im using Rave report tool to making reports for my applications written by Delphi
I'm making a game in actionscript using the FlashDevelop tool and the FlashPunk game
I was wondering if there is any tool that renames folder really quickly, using
I'm writing a little JavaScript tool for myself that I plan on making available
I am making a PHP tool that connects to a repository, downloads the list
I'm making some load test using Siege and Apache benchmarking tool . I count
I am testing a QT C++ application using QNetworkAccessManager that is successfully making HTTP
I am working on making a loupe tool using C#. Much like this one:

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.