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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:09:39+00:00 2026-05-22T16:09:39+00:00

I have a for each loop that runs through the database to check for

  • 0

I have a for each loop that runs through the database to check for files that have been flagged for conversion. Currently I have the following code:

            /* All files flagged for invidual conversion will be stored in here. */
            ArrayList files = vc.getFilesForInvidualConversion();
            foreach (FileInfoExtended file in files)
            {
                // As long as the status flag hasn't been changed it can continue.
                if (abort == false)
                {
                    if (vc.isFileInUse(file) == false)
                    {
                            // Converting the video file.
                            vc.convertVideoToFLV(file);
                    }
                }
                vc.getFilesForInvidualConversion();
            }

In the first line you can see I fill an ArrayList with objects which it will run through with a for each. However, after each file in the list I want to check for possible new files that need to be converted. When I fill the ArrayList again the for each doesn’t seem to notice, it keeps working with the original files received from the first line of code. I’d rather want it to update the “files”-ArrayList so that it can convert the new files as well.

Is this possible?

EDIT: The anwsers you gave all work for this scenario, but I want to add something. Is it possible to remove a file from the list during the loop? And to make it so it won’t convert that one?

EDIT 2: This is what I have now:

            List<FileInfoExtended> files = vc.getFilesForInvidualConversion();
            while (files.Count > 0)
            {
                if (abort == false)
                {
                    if (vc.isFileInUse(files[0]))
                    {
                        vc.convertVideoToFLV(files[0]);
                    }
                }
                files = vc.getFilesForInvidualConversion();
            }

And it works in both cases (when a file is added to the list and when a file is removed from the list). I don’t know if it is performance wise a good solution, but right now it suits my needs. Unless there are some issues I’m overlooking?

Any comment will be appreciated!
Kind regards,
Floris

  • 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-22T16:09:40+00:00Added an answer on May 22, 2026 at 4:09 pm

    You can use a standard ‘for’ loop. foreach loops require the collection to be immutable during traversal. A ‘for’ loop doesn’t have this constraint. However, getting the ending condition constraints on a ‘for’ loop might be difficult in this case.

    I would consider keeping a list of the files already processed so that when you make you second pass, you can just check to see if you have already handled a particular file.

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

Sidebar

Related Questions

I have a loop that runs through each column and sets the value to
I have a loop that runs through a text area's line and processes each
The following code returns the error from the For Each loop. I have similar
I have a do/while loop that goes over database rows. Because it runs many
I have the following situation: I have a certain function that runs a loop
I am building a chess game and i have a loop that runs through
I have a for loop that runs through an array of functions and invokes
I have a loop that runs through an array of image views, adding an
I have a script that runs through a multi-level array and each time calls
I have a loop that reads each line in a file using getline() :

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.