Find Files in certain directory

CK CK 3788 
Created at
Updated at  
937 0 0

The DirectoryInfo class in C# represents a directory on your computer's file system. It provides methods for interacting with the directory, such as creating new directories, deleting existing ones, checking if a directory exists, listing the files and subdirectories within it, getting its attributes (like read-only status or hidden status), and obtaining its full path and name.

FileInfo class provides a way to interact with individual files on your computer. It allows you to access file properties like name, size, creation date, last access time, and more. You can also use it to perform actions like reading file contents, writing to files, deleting files, and moving or copying files. FileInfo offers a convenient and structured approach to manage file-related operations within your C# applications. 

Following is the simple C# example to fins file in given directory.
 

using System.IO; // added for FileInfo class

.
.
.
.

DirectoryInfo dir = new DirectoryInfo(@"F:\WINNT");
FileInfo[] bmpfiles = dir.GetFiles("*.bmp");
Console.WriteLine("Total number of bmp files", bmpfiles.Length);
foreach( FileInfo f in bmpfiles)
{
  Console.WriteLine("Name is : {0}", f.Name);
  Console.WriteLine("Length of the file is : {0}", f.Length);
  Console.WriteLine("Creation time is : {0}", f.CreationTime);
  Console.WriteLine("Attributes of the file are : {0}",
                     f.Attributes.ToString());
}


 

Tags DirectoryInfo FileInfo Facebook X
Comments 0
  1. How to convert text string to integer ?
    616
  2. How to set an certain color as transparent color on bitmap
    526
  3. How to resize and save PNG or Jpeg Image file ?
    638
  4. How to display message box in C#
    1,129
  5. How to convert bitmap image to jpeg image ?
    362
  6. To load image from file
    457
  7. URL Encode, Decode function for MFC
    609
  8. How to load HTML resource on MFC ?
    848
  9. How to get GM Time as String ?
    424
  10. Makefile to automate the build process for C++
    285
  11. Finding process name on OS
    414
  12. Convert System.DateTime to UNIX timestamp
    386
  13. Retrieve system information
    498
  14. How to call SetTimer function on MFC CDialog class ?
    652
  15. How to rename(change file name) in C# ?
    1,086
  16. Implementing C#'s foreach loop in Delphi 8
    463
  17. How to detect resource leaks in a Form
    950
  18. The best way to enable and disable buttons, menu items and toolbar buttons
    668
  19. How to exit from a console application
    816
  20. How to restrict a program to a single instance
    733
  21. Compress and decompress strings in C#
    977
  22. Graphics in C# - Irregular Forms
    914
  23. Extracting the Country from IP Address
    471
  24. How to run shell command by MFC ?
    441
  25. Binary Search Sample Code
    409
  26. Double Linked List based in C++
    800
  27. String Replace Function For C#
    1,561
  28. How to print character in C# by ASCII code
    480
  29. MFC based World Wide Web HTTP Server Source Code
    463
  30. Creating and Using a CAsyncSocket Object to use CAsyncSocket
    473
Recently updated
  1. Google OAuth Token Expiration: Causes and Solutions
    31
  2. Why 100% SEO Guarantees Better User Engagement and How to Achieve It in Your Service
    57
  3. Why SPF and DKIM Are Essential for Linux Email Servers?
    51
  4. How do I create animated background for Google Meet?
    23,256
  5. MaxMind GeoLite2 vs. DB-IP Lite vs. ip-api.com: Choosing the Right Free IP Geolocation Solution
    273
  6. Meet Valkey: Why Redis Changed Its License, Why Valkey is Better, and How to Use It as a Drop-in Replacement
    105
  7. How Rogue Web Scrapers Are Stealing My Content and Destroying My Server
    170
  8. Array of arguments passed to script in PHP
    99
  9. Invalid Auction Storms in Ad Tech
    108
  10. Building MRC-Compliant Instrumentation in Ad Tech: Implementation Steps and Key Challenges
    209
  11. The Two Clocks of Ad Server Architecture
    78
  12. Frequency Cap Architecture Overview
    527
  13. Collecting Proof-of-Play from 100,000 Screens
    154
  14. Vector Search in Relational Databases (RDBs): Trends & Usage Environments
    303
  15. What is RedisVL?
    117
  16. Designing a Skill Registry Architecture: Minimize Token Usage and Maximize AI Performance
    247
  17. TPU & GPU Cluster Management Tools
    258
  18. The Concept of Scaffolding in AI Agents
    245
  19. Beyond Static Pipelines: Architecting LLM Multi-Agent Systems for Autonomous Workflow Orchestration
    599
  20. AI-DLC vs. AI-SDLC: Model-Centric vs. System-Centric AI Development
    269
  21. Fine-Tuning Open-Weight LLMs: Training, Licensing, and Deploying Custom Models with Ollama
    355
  22. Inside the Next-Generation Streaming Architecture: Ultra-Low Latency, SGAI, and AI Codecs
    207
  23. Machine Learning: Training vs. Ranking
    231
  24. The Continuous Learning Machine: Designing a Loop That Actually Turns
    229
  25. The Next-Gen Low-Latency Standards: LL-HLS & MoQ
    204
  26. Designing a Data Curation System Around a Vector Database
    230
  27. Extracting Context from Live Video: The Architecture Got Simpler When We Stopped Building Features
    263
  28. The New Ad Stack Behind Live Sports Streaming: Inside SGAI, EABN, and the Standards Race to Fix Live Monetization
    674
  29. Designing MLOps Architectures to Handle Seasonal Data Drift in EV Fleet Models
    201
  30. From 15 to 40+ FPS: Accelerating PyTorch Object Detection on Automotive ECUs
    233