Operations on files obtained by Directory.EnumerateFiles never finish

OHASHI RURI(大橋 瑠璃) 0 Reputation points
2025-03-12T10:35:12.27+00:00

【概要】

.netFramework 4.7を利用したプログラムにおいて

Directory.EnumerateFilesで取得したファイル一覧に対して

FOR文によるファイル操作を実施した場合に、処理が終わらない事象が発生しております。

既知事象の有無及び、改善策があればご教授頂けないでしょうか。

【実行環境】

OS:Windows Server2022

【処理詳細】

処理の詳細は以下の通りです。

 ①Directory.EnumerateFilesメソッドを利用

  ワイルドカードを利用し、指定文字を含むファイル名の一覧を取得

 ②取得済のファイル一覧を「For Each」でループし、1ファイルずつ操作を行う。

.NET Runtime
.NET Runtime
.NET: Microsoft Technologies based on the .NET software framework.Runtime: An environment required to run apps that aren't compiled to machine language.
1,199 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Jiachen Li-MSFT 33,781 Reputation points Microsoft External Staff
    2025-03-12T13:58:27.0166667+00:00

    Hi @Anonymous ,

    If you have a large number of files, process them in batches. This can help avoid memory issues and improve performance.

    Consider using asynchronous methods to perform file operations. This can help keep your application responsive and improve overall performance.

    Best Regards.

    Jiachen Li


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.