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

  • SEARCH
  • Home
  • 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 8510995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:51:50+00:00 2026-06-11T03:51:50+00:00

I have a function that checks for presence of files in a particular folder

  • 0

I have a function that checks for presence of files in a particular folder and if the files have the data that is not present in the main database i write that data to main db and delete the file i am using Directory.EnumerateFiles to get the list of files and then i iterate through this list to check if they are present in the db, i want to return from the function if the list is empty how to check if list that i got is empty,if i debug and the folder has no files it shows Enumeration did not produce the results.

    private void GetListOfFiles()
    {
        string sourceDirectory = pathOfXmlFiles;
        if (!Directory.Exists(sourceDirectory))
        {
            return;
        }
        var xmlFiles = Directory.EnumerateFiles(sourceDirectory, "*.xml");
        foreach (var item in xmlFiles)
        {
            ReadXmlFile(item);
        }
        foreach (var item in xmlFiles)
        {
            if (_writtenToDb)
            {
                File.Delete(item);
            }
        }
    }

i check for the presence of these files using a different thread that has a timer that fires every 25 seconds , i never do stop the timer can this lead to memory leaks?

  • 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-11T03:51:51+00:00Added an answer on June 11, 2026 at 3:51 am

    You don’t need to do anything. If xmlFiles is empty both foreach loops won’t do anything since there are no objects to iterate over.

    However, if you really need to explicitly return if there are no files, use this:

    if(!xmlFiles.Any())
        return;
    

    Dont forget to add using System.Linq; at the top of your source file.


    As you are enumerating multiple times over the returned files, I suggest you use Directory.GetFiles instead. This will return an array with all files. This will avoid multiple hits to the disk for querying the existing files.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a function that checks if to files are duplicates or not.
I'm using the HTML5 Web Database API and I have a function that checks
I have a function that checks if a cookie (by name) exists or not:
I have a function that checks for a particular event and when it detects
If I have a function that checks the database to see if a username
I have a function that checks to see whether or not a request has
I have a function that checks whether the plist exists or not, if not
I have a function that checks whether or not the vertex/fragment shared was compiled
On my program I have a function that checks for the current version of
I have a callback function that checks my login details are correct - If

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.