.NET 도움말 C# Directory.GetFiles (How It Works: A Guide for Developers) 커티스 차우 업데이트됨:6월 22, 2025 다운로드 IronPDF NuGet 다운로드 DLL 다운로드 윈도우 설치 프로그램 무료 체험 시작하기 LLM용 사본 LLM용 사본 LLM용 마크다운 형식으로 페이지를 복사하세요 ChatGPT에서 열기 ChatGPT에 이 페이지에 대해 문의하세요 제미니에서 열기 제미니에게 이 페이지에 대해 문의하세요 Grok에서 열기 Grok에게 이 페이지에 대해 문의하세요 혼란 속에서 열기 Perplexity에게 이 페이지에 대해 문의하세요 공유하다 페이스북에 공유하기 트위터에 공유하기 LinkedIn에 공유하기 URL 복사 이메일로 기사 보내기 C# out parameter. By pairing this functionality with IronPDF, developers can automate PDF workflows at scale. For example, you can use Directory.GetFiles to locate all PDF files in a folder, then process them in bulk using IronPDF for tasks such as merging, adding annotations, or generating reports. This combination allows for streamlined operations, especially when dealing with many files in the file system. What is IronPDF? IronPDF is a robust .NET library that provides developers with tools to work seamlessly with PDF files. With IronPDF, you can create, edit, merge, split, and manipulate PDFs using straightforward, intuitive methods. It includes powerful features such as HTML-to-PDF conversion, advanced styling, and metadata handling. For .NET developers working on applications that require PDF processing, IronPDF is an invaluable tool that streamlines workflows and enhances productivity. Getting Started Installing IronPDF NuGet Package Installation To begin, add IronPDF to your project via NuGet: Open your project in Visual Studio. Go to the Tools menu and select NuGet Package Manager > Manage NuGet Packages for Solution. Search for IronPDF in the NuGet package manager. Install the latest version of IronPDF. Alternatively, use the NuGet Package Manager Console: Install-Package IronPdf Basics of Directory.GetFiles in C# The Directory.GetFiles method is part of the System.IO namespace and is used to retrieve file names from a file system. This method, a public static string member of the Directory class, simplifies accessing file paths. For instance: string[] pdfFiles = Directory.GetFiles("C:\\Documents\\PDFs", "*.pdf"); string[] pdfFiles = Directory.GetFiles("C:\\Documents\\PDFs", "*.pdf"); $vbLabelText $csharpLabel This snippet retrieves all PDF files within the current directory. By combining this method with IronPDF, you can create automated solutions for processing multiple files at once. You can also apply a specified search pattern, defined as a string pattern, to filter files based on their extensions or names. You can further refine your file retrieval logic by specifying search options, such as including search subdirectories: string[] pdfFiles = Directory.GetFiles("C:\\Documents\\PDFs", "*.pdf", SearchOption.AllDirectories); string[] pdfFiles = Directory.GetFiles("C:\\Documents\\PDFs", "*.pdf", SearchOption.AllDirectories); $vbLabelText $csharpLabel This ensures that files in nested folders are also included, retrieving each file's absolute path and making the approach versatile for various scenarios. Practical Use Cases Fetching and Processing PDF Files from a Directory Example: Loading All PDF Files for Processing Using Directory.GetFiles, you can iterate over all PDF files in a directory and process them with IronPDF: string[] pdfFiles = Directory.GetFiles("C:\\Documents\\PDFs", "*.pdf"); foreach (string file in pdfFiles) { // Load the PDF with IronPDF var pdf = PdfDocument.FromFile(file); Console.WriteLine($"Processing file: {Path.GetFileName(file)}"); } string[] pdfFiles = Directory.GetFiles("C:\\Documents\\PDFs", "*.pdf"); foreach (string file in pdfFiles) { // Load the PDF with IronPDF var pdf = PdfDocument.FromFile(file); Console.WriteLine($"Processing file: {Path.GetFileName(file)}"); } $vbLabelText $csharpLabel This example demonstrates how to load multiple PDFs from a directory for processing. Once loaded, you can perform a variety of operations, such as extracting text, adding annotations, or generating new PDFs based on their content. Filtering Files Using Search Patterns Example: Selecting PDFs by Name or Date You can combine Directory.GetFiles with LINQ to filter files based on criteria such as creation or modification date: string[] pdfFiles = Directory.GetFiles("C:\\Documents\\PDFs", "*.pdf"); var recentFiles = pdfFiles.Where(file => File.GetLastWriteTime(file) > DateTime.Now.AddDays(-7)); foreach (string file in recentFiles) { Console.WriteLine($"Recent file: {Path.GetFileName(file)}"); } string[] pdfFiles = Directory.GetFiles("C:\\Documents\\PDFs", "*.pdf"); var recentFiles = pdfFiles.Where(file => File.GetLastWriteTime(file) > DateTime.Now.AddDays(-7)); foreach (string file in recentFiles) { Console.WriteLine($"Recent file: {Path.GetFileName(file)}"); } $vbLabelText $csharpLabel This approach ensures that only relevant files are processed, saving time and computational resources. For example, you might use this method to process only the latest invoices or reports generated within the last week. Batch Operations with IronPDF and Directory.GetFiles Example: Appending Multiple PDFs You can append multiple PDFs from a directory into a single file: string[] pdfFiles = Directory.GetFiles("C:\\Documents\\PDFs", "*.pdf"); var pdfAppend = new PdfDocument(200, 200); foreach (string file in pdfFiles) { var pdf = PdfDocument.FromFile(file); pdfAppend.AppendPdf(pdf); } pdfAppend.SaveAs("LargePdf.pdf"); Console.WriteLine("PDFs Appended successfully!"); string[] pdfFiles = Directory.GetFiles("C:\\Documents\\PDFs", "*.pdf"); var pdfAppend = new PdfDocument(200, 200); foreach (string file in pdfFiles) { var pdf = PdfDocument.FromFile(file); pdfAppend.AppendPdf(pdf); } pdfAppend.SaveAs("LargePdf.pdf"); Console.WriteLine("PDFs Appended successfully!"); $vbLabelText $csharpLabel This approach is particularly useful for creating consolidated reports, archiving multiple documents, or preparing presentations. By automating this process, you can handle large collections of files effortlessly. Step-by-Step Implementation Setting Up the Project Code Snippet: Initializing IronPDF and Working with PDF Files The following code demonstrates how IronPDF can be used alongside Directory.GetFiles to load and work with PDF documents. using IronPdf; using System; using System.IO; class Program { static void Main() { // Retrieve all PDF file paths from the specified directory string[] pdfFiles = Directory.GetFiles("C:\\Users\\kyess\\Documents\\PDFs", "*.pdf"); // Initialize a PdfDocument var pdfAppend = new PdfDocument(200, 200); // Create a text annotation to add to each PDF TextAnnotation annotation = new TextAnnotation(0) { Contents = "Processed by IronPDF", X = 50, Y = 50, }; // Iterate over each file path, load, annotate, and save foreach (string file in pdfFiles) { var pdf = PdfDocument.FromFile(file); pdf.Annotations.Add(annotation); pdf.SaveAs(file); } } } using IronPdf; using System; using System.IO; class Program { static void Main() { // Retrieve all PDF file paths from the specified directory string[] pdfFiles = Directory.GetFiles("C:\\Users\\kyess\\Documents\\PDFs", "*.pdf"); // Initialize a PdfDocument var pdfAppend = new PdfDocument(200, 200); // Create a text annotation to add to each PDF TextAnnotation annotation = new TextAnnotation(0) { Contents = "Processed by IronPDF", X = 50, Y = 50, }; // Iterate over each file path, load, annotate, and save foreach (string file in pdfFiles) { var pdf = PdfDocument.FromFile(file); pdf.Annotations.Add(annotation); pdf.SaveAs(file); } } } $vbLabelText $csharpLabel Console Output Explanation This code demonstrates how to add a text annotation to all PDF files in a specified directory using IronPDF in C#. The program begins by retrieving all PDF file paths from the folder provided using the Directory.GetFiles method, which relies on a string path to specify the directory and supports filtering by file extension, returning an array of string filenames containing the paths of all PDF files with the ".pdf" extension. Next, the code initializes a PdfDocument object (pdfAppend) with dimensions 200x200, although this specific instance isn't used directly in the loop. It then creates a TextAnnotation with the text "Processed by IronPDF" positioned at coordinates (50, 50). This annotation will be added to each PDF file. In the foreach loop, the program iterates through each file path in the pdfFiles array. For each file, it loads the PDF using PdfDocument.FromFile(file), adds the previously created annotation to the PDF's Annotations collection, and then saves the updated PDF back to its absolute path using pdf.SaveAs(file). This process ensures that every PDF in the specified directory receives the same annotation and is saved with the annotation included. Performance Tips and Best Practices Optimizing File Retrieval with Directory.GetFiles Use asynchronous methods like Directory.EnumerateFiles for better performance with large directories. Managing Large Numbers of Files Efficiently Process files in smaller batches to reduce memory consumption: foreach (var batch in pdfFiles.Batch(10)) { foreach (string file in batch) { var pdf = PdfDocument.FromFile(file); // Process PDF } } foreach (var batch in pdfFiles.Batch(10)) { foreach (string file in batch) { var pdf = PdfDocument.FromFile(file); // Process PDF } } $vbLabelText $csharpLabel Error Handling in File Processing and PDF Generation Wrap file processing in a try-catch block to handle exceptions: try { var pdf = PdfDocument.FromFile(file); // Process PDF } catch (Exception ex) { Console.WriteLine($"Error processing {file}: {ex.Message}"); } try { var pdf = PdfDocument.FromFile(file); // Process PDF } catch (Exception ex) { Console.WriteLine($"Error processing {file}: {ex.Message}"); } $vbLabelText $csharpLabel Conclusion Combining the power of Directory.GetFiles with IronPDF allows developers to efficiently manage and process PDF files at scale. With this approach, tasks such as batch processing, merging, filtering, and transforming PDFs become seamless, significantly reducing manual effort and improving productivity. By leveraging the advanced capabilities of IronPDF, including adding headers, metadata, and styling, developers can create high-quality, professional PDF documents tailored to their requirements. Throughout this guide, we’ve explored how to use Directory.GetFiles to retrieve and manipulate PDFs with IronPDF. From setting up a project to implementing practical use cases, we covered essential techniques that can be applied to real-world scenarios. Whether you are working on automating document workflows or enhancing the functionality of your .NET applications, this combination provides a robust and scalable solution. If you're ready to dive deeper into IronPDF and explore advanced features, consider referring to the official documentation, allowing you to test the library in your own projects. 자주 묻는 질문 C#에서 Directory.GetFiles 메서드는 어떻게 작동하나요? C#의 Directory.GetFiles 메서드는 개발자가 지정된 디렉터리에서 파일 경로를 검색할 수 있도록 하는 System.IO 네임스페이스의 일부입니다. 이 메서드는 검색 패턴과 하위 디렉터리를 포함하는 옵션을 지원하므로 특정 파일 유형이나 이름에 액세스하는 데 효율적입니다. C#을 사용하여 PDF 파일 처리를 자동화하려면 어떻게 해야 하나요? Directory.GetFiles 메서드와 함께 IronPDF를 사용하면 C#에서 PDF 파일 처리를 자동화할 수 있습니다. 이를 통해 디렉토리에서 PDF 파일을 찾고 병합, 주석 추가 또는 보고서 자동 생성과 같은 작업을 수행할 수 있습니다. Directory.GetFiles와 PDF 라이브러리를 결합하면 어떤 이점이 있나요? Directory.GetFiles를 IronPDF와 같은 PDF 라이브러리와 결합하면 PDF 문서를 자동화하고 효율적으로 관리할 수 있습니다. PDF를 대량으로 가져와 처리하고, 수정 사항을 적용하고, 파일을 통합하여 생산성을 높이고 수작업을 줄일 수 있습니다. C#을 사용하여 여러 PDF를 하나의 문서에 추가하려면 어떻게 해야 하나요? 여러 PDF를 하나의 문서에 추가하려면 Directory.GetFiles를 사용하여 디렉토리에 있는 모든 PDF 파일을 검색합니다. 그런 다음 각 PDF를 IronPDF로 로드하여 하나의 PdfDocument 객체에 추가하면 통합된 PDF 파일로 저장할 수 있습니다. C#에서 생성 날짜별로 디렉토리 파일을 필터링하려면 어떻게 해야 하나요? Directory.GetFiles와 함께 LINQ를 사용하여 생성 날짜별로 디렉토리 파일을 필터링할 수 있습니다. 예를 들어 지난 주에 만든 파일을 선택하려면 다음과 같이 하세요: var recentFiles = pdfFiles.Where(file => File.GetCreationTime(file) > DateTime.Now.AddDays(-7)); C#으로 대량의 파일을 처리하는 모범 사례는 무엇인가요? 많은 수의 파일을 처리할 때는 Directory.EnumerateFiles와 같은 비동기 메서드를 사용하여 검색 시간을 단축하여 성능을 개선하세요. 이 방법은 대용량 디렉터리를 효율적으로 처리할 때 특히 유용합니다. C#에서 PDF 파일을 처리하는 동안 발생하는 오류는 어떻게 처리하나요? 트라이 캐치 블록으로 작업을 래핑하여 PDF 파일 처리 중 오류를 처리합니다. 이렇게 하면 예외가 원활하게 관리되므로 예기치 않은 오류로 인해 애플리케이션이 충돌하지 않고 계속 실행될 수 있습니다. C#에서 PDF 라이브러리를 사용한 일괄 처리의 예는 무엇인가요? 일괄 처리의 한 예로 Directory.GetFiles를 사용하여 PDF를 검색한 다음 IronPDF를 사용하여 일괄 병합하거나 주석을 다는 것을 들 수 있습니다. 이 접근 방식은 반복적인 작업을 자동화하여 시간과 노력을 절약합니다. .NET 라이브러리를 사용하여 PDF에 텍스트 주석을 추가하려면 어떻게 해야 하나요? IronPDF를 사용하여 PDF에 텍스트 주석을 추가하려면 지정된 콘텐츠와 위치로 TextAnnotation 개체를 만듭니다. 각 PDF를 로드하고 해당 주석 컬렉션에 주석을 추가한 다음 업데이트된 문서를 저장합니다. Visual Studio에서 NuGet을 통해 PDF 라이브러리를 설치하는 단계는 무엇인가요? Visual Studio에서 NuGet을 통해 PDF 라이브러리를 설치하려면 프로젝트를 열고 도구 > NuGet 패키지 관리자 > 솔루션용 NuGet 패키지 관리로 이동하여 IronPDF를 검색한 후 설치하세요. 또는 다음 명령과 함께 NuGet 패키지 관리자 콘솔을 사용하세요: Install-Package IronPdf. 커티스 차우 지금 바로 엔지니어링 팀과 채팅하세요 기술 문서 작성자 커티스 차우는 칼턴 대학교에서 컴퓨터 과학 학사 학위를 취득했으며, Node.js, TypeScript, JavaScript, React를 전문으로 하는 프론트엔드 개발자입니다. 직관적이고 미적으로 뛰어난 사용자 인터페이스를 만드는 데 열정을 가진 그는 최신 프레임워크를 활용하고, 잘 구성되고 시각적으로 매력적인 매뉴얼을 제작하는 것을 즐깁니다. 커티스는 개발 분야 외에도 사물 인터넷(IoT)에 깊은 관심을 가지고 있으며, 하드웨어와 소프트웨어를 통합하는 혁신적인 방법을 연구합니다. 여가 시간에는 게임을 즐기거나 디스코드 봇을 만들면서 기술에 대한 애정과 창의성을 결합합니다. 관련 기사 업데이트됨 12월 11, 2025 Bridging CLI Simplicity & .NET : Using Curl DotNet with IronPDF Jacob Mellor has bridged this gap with CurlDotNet, a library created to bring the familiarity of cURL to the .NET ecosystem. 더 읽어보기 업데이트됨 12월 20, 2025 RandomNumberGenerator C# Using the RandomNumberGenerator C# class can help take your PDF generation and editing projects to the next level 더 읽어보기 업데이트됨 12월 20, 2025 C# String Equals (How it Works for Developers) When combined with a powerful PDF library like IronPDF, switch pattern matching allows you to build smarter, cleaner logic for document processing 더 읽어보기 C# Convert String to Bubble (How it Works for Developers)C# Out Parameter (How It Works: A G...
업데이트됨 12월 11, 2025 Bridging CLI Simplicity & .NET : Using Curl DotNet with IronPDF Jacob Mellor has bridged this gap with CurlDotNet, a library created to bring the familiarity of cURL to the .NET ecosystem. 더 읽어보기
업데이트됨 12월 20, 2025 RandomNumberGenerator C# Using the RandomNumberGenerator C# class can help take your PDF generation and editing projects to the next level 더 읽어보기
업데이트됨 12월 20, 2025 C# String Equals (How it Works for Developers) When combined with a powerful PDF library like IronPDF, switch pattern matching allows you to build smarter, cleaner logic for document processing 더 읽어보기